Skip to content

util/gconv: Fields with the same name in nested structures overwrite values #3797

@wln32

Description

@wln32

Go version

1.22

GoFrame version

2.7.3

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

type Rule struct {
	ID int64 `json:"id"`
	Rule []*option.Rule `json:"rule"`
}

type Res1 struct {
	g.Meta
	Rule
}

var err error
var r = &Rule{
	ID: 100,
}
var res = &Res1{}
if err = gconv.Scan(r, res); err != nil {
	fmt.Println("err=", err)
	return
}
for {
	if res.ID == 0 {
		fmt.Println("res.id")
		g.Dump(res)
		fmt.Printf("%+v\n", res)
		time.Sleep(time.Second)
	}
}

What did you see happen?

res.id
{
    ID:   0,
    Rule: {
        ID:   0,
        Rule: [],
    },
}
&{Meta:{} Rule:{ID:0 Rule:[]}}

What did you expect to see?

什么都不输出,赋值正确即可

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIt is confirmed a bug, but don't worry, we'll handle it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions