Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result when nested struct #339

Closed
jinleiw opened this issue Mar 19, 2020 · 1 comment · Fixed by #340
Closed

Unexpected result when nested struct #339

jinleiw opened this issue Mar 19, 2020 · 1 comment · Fixed by #340

Comments

@jinleiw
Copy link
Contributor

jinleiw commented Mar 19, 2020

Describe the bug
For nested struct,if there are attributes with same name, parse result is not expected.

To Reproduce

type Server struct {
    Name string `toml:"name" default:"noname"`
    Inter2 Inter2 `toml:"inter2"`
}

type Inter2 struct {
    Name         string
    Age          int
    InterStruct2 InterStruct2
}

type InterStruct2 struct {
    Test string
    Name string
    Age  int
}
var server Server

err := toml.Unmarshal([]byte(`name = "123"

[inter2]
	name = "inter2"
	age = 222`), &server)

Expected behavior
Expected value of server:

{Name:"123", Inter2:{Name:"inter2", Age:222, InterStruct2:{Test:"", Name:"", Age:0}}}

but got:

{Name:"123", Inter2:{Name:"inter2", Age:222, InterStruct2:{Test:"", Name:"inter2", Age:222}}}

Versions

  • go-toml: master
  • go: 1.13.8
  • operating system: Windows
AllenX2018 added a commit to AllenX2018/go-toml that referenced this issue Mar 19, 2020
pelletier pushed a commit that referenced this issue Mar 23, 2020
@pelletier
Copy link
Owner

@jinleiw Thank you for your bug report! Just merged @AllenX2018's patch, which should have fixed the problem. If you are still experiencing the issue with the latest master code, feel free to reopen this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants