Skip to content

Duplicate key error when using multiple merge anchors (<<) with the same key in YAML #26

@Dmitry-True

Description

@Dmitry-True

Description:

When parsing a YAML document that contains multiple merge anchors (<<: *anchor) in the same mapping — even if they reference different anchors — the ConvertFrom-Yaml command throws an error:

ConvertFrom-Yaml : Duplicate key <<
This occurs even though the YAML is syntactically valid and the merge keys are intended to apply multiple anchor expansions in sequence (as allowed by the YAML spec).

Example to Reproduce:

$actual = ConvertFrom-Yaml @'
dict:
  test: &anchor2
    key5: value
    key6: test value
  entry1: &anchor
    key1: value 1
    key2: value 2
  entry2:
    <<: *anchor
    key2: other value
    key3: final value
  entry3:
    key2: other value
    key3: final value
    <<: *anchor
    <<: *anchor2
'@ -Schema Yaml11

Expected Behavior:

The command should successfully parse the YAML, merging the content from both *anchor and *anchor2 into entry3. The resulting structure should include all keys from both anchors, with later keys overriding earlier ones if there are conflicts (per YAML merge key semantics).

Notes:

The YAML specification allows multiple << keys in a single mapping (though it's rare), and some YAML parsers handle this by merging each anchor in order.
Even if the behavior should be modified (e.g., to warn or merge sequentially), the current implementation should not fail outright unless explicitly designed to reject such constructs.
At minimum, the error message should be more descriptive if multiple merge keys are intentionally disallowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions