Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,14 +1117,14 @@ func (d *Decoder) createDecodedNewValue(
return d.castToAssignableValue(newValue, typ, node)
}

func (d *Decoder) keyToNodeMap(ctx context.Context, node ast.Node, ignoreMergeKey bool, getKeyOrValueNode func(*ast.MapNodeIter) ast.Node) (map[string]ast.Node, error) {
func (d *Decoder) _keyToNodeMap(ctx context.Context, node ast.Node, ignoreMergeKey bool, isMerge bool, getKeyOrValueNode func(*ast.MapNodeIter) ast.Node) (map[string]ast.Node, error) {
d.stepIn()
defer d.stepOut()
if d.isExceededMaxDepth() {
return nil, ErrExceededMaxDepth
}

mapNode, err := d.getMapNode(node, false)
mapNode, err := d.getMapNode(node, isMerge)
if err != nil {
return nil, err
}
Expand All @@ -1137,7 +1137,7 @@ func (d *Decoder) keyToNodeMap(ctx context.Context, node ast.Node, ignoreMergeKe
if ignoreMergeKey {
continue
}
mergeMap, err := d.keyToNodeMap(ctx, mapIter.Value(), ignoreMergeKey, getKeyOrValueNode)
mergeMap, err := d._keyToNodeMap(ctx, mapIter.Value(), ignoreMergeKey, true, getKeyOrValueNode)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1165,6 +1165,10 @@ func (d *Decoder) keyToNodeMap(ctx context.Context, node ast.Node, ignoreMergeKe
return keyToNodeMap, nil
}

func (d *Decoder) keyToNodeMap(ctx context.Context, node ast.Node, ignoreMergeKey bool, getKeyOrValueNode func(*ast.MapNodeIter) ast.Node) (map[string]ast.Node, error) {
return d._keyToNodeMap(ctx, node, ignoreMergeKey, false, getKeyOrValueNode)
}

func (d *Decoder) keyToKeyNodeMap(ctx context.Context, node ast.Node, ignoreMergeKey bool) (map[string]ast.Node, error) {
m, err := d.keyToNodeMap(ctx, node, ignoreMergeKey, func(nodeMap *ast.MapNodeIter) ast.Node { return nodeMap.Key() })
if err != nil {
Expand Down
57 changes: 57 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,63 @@ merge:
"merge": {{Key: "foo", Value: 1}, {Key: "bar", Value: 2}},
},
},
// Issue #776
{
source: `
a: &a
value: 100

b: &b
unit: "m/s"

c:
<<: [*a, *b]
d: var_x
`,
value: struct {
C struct {
Value int `yaml:"value"`
Unit string `yaml:"unit"`
D string `yaml:"d"`
} `yaml:"c"`
}{
C: struct {
Value int `yaml:"value"`
Unit string `yaml:"unit"`
D string `yaml:"d"`
}{
Value: 100,
Unit: "m/s",
D: "var_x",
},
},
},
{
source: `
a: &a
value: 100

b: &b
unit: "m/s"

c:
<<: [*a, *b]
d: var_x
`,
value: map[string]any{
"c": map[string]any{
"value": 100,
"unit": "m/s",
"d": "var_x",
},
"a": map[string]any{
"value": 100,
},
"b": map[string]any{
"unit": "m/s",
},
},
},

// Flow sequence
{
Expand Down
Loading