Skip to content

Commit

Permalink
fix behavior when struct fields conflicted (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Dec 19, 2022
1 parent 458cd4e commit 9044eca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions decode_test.go
Expand Up @@ -2804,3 +2804,21 @@ steps:
})
}
}

func TestSameNameInineStruct(t *testing.T) {
type X struct {
X float64 `yaml:"x"`
}

type T struct {
X `yaml:",inline"`
}

var v T
if err := yaml.Unmarshal([]byte(`x: 0.7`), &v); err != nil {
t.Fatal(err)
}
if fmt.Sprint(v.X.X) != "0.7" {
t.Fatalf("failed to decode")
}
}
2 changes: 1 addition & 1 deletion struct.go
Expand Up @@ -95,7 +95,7 @@ type StructFieldMap map[string]*StructField

func (m StructFieldMap) isIncludedRenderName(name string) bool {
for _, v := range m {
if v.RenderName == name {
if !v.IsInline && v.RenderName == name {
return true
}
}
Expand Down

0 comments on commit 9044eca

Please sign in to comment.