-
-
Notifications
You must be signed in to change notification settings - Fork 211
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When attempting to parse a YAML file containing multiple merged anchors (<<: [*a, *b]), the parsing fails with the following trace:
panic: [8:7] sequence was used where mapping is expected
5 | unit: "m/s"
6 |
7 | c:
> 8 | <<: [*a, *b]
^
9 | d: var_x
10 |
goroutine 1 [running]:
main.main()
C:/Users/-/GolandProjects/awesomeProject/main.go:139 +0xd4
Process finished with the exit code 2
To Reproduce
For the following yaml file:
a: &a
value: 100
b: &b
unit: "m/s"
c:
<<: [*a, *b]
d: var_x
I defined Go structs as :
type C struct {
Value int `yaml:"value"`
Unit string `yaml:"unit"`
D string `yaml:"d"`
}
type RootNode struct {
C C `yaml:"c"`
}
and tried to unmarshall
var yamlStuct RootNode
yamlFileBytes, _ := os.ReadFile("test_multi_merge.yml")
if err := yaml.Unmarshal(yamlFileBytes, &yamlStuct); err != nil {
panic(err)
}
fmt.Printf("Parsed YAML: %+v\n", yamlStuct)
However if I modify the yaml file to inclue the keys directly, it works as expected
a: &a
value: 100
b: &b
unit: "m/s"
c:
value: 100
unit: "m/s"
d: var_x
Expected behavior
the struct should be populated with: {C:{Value:100 Unit:m/s D:var_x}}
Version Variables
- Go version: go version go1.24.2 windows/amd64
- go-yaml's Version: v1.18.0
Additional context
I understand that merge keys is deprecated and is supposed to be replaced by somthing new according to this but that was written a while ago so I'm not sure about the status on that.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working