-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/json: json.Marshal does not error with name conflicts between anonymous structs #8121
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
Labels
Milestone
Comments
CL https://golang.org/cl/102030043 mentions this issue. |
Can you please try this CL https://golang.org/cl/102030043? |
CL https://golang.org/cl/145820044 mentions this issue. |
Your CL makes reference to V8 and Python. That's not interesting. This is Go. The Go rule is that if you have two embedded structs with the same field name at the same depth in a struct type, that field name is not accessible from the top level of the struct using the . operator. json.Marshal uses all the fields that are accessible from the top level using the . operator. If there are JSON-specific tag overrides, it applies the same Go rule to those instead of the Go field names. But either way it is the Go semantics that are being used here, not anything defined by JSON or V8 or Python. To be very concrete, here is an edited version of your program: http://play.golang.org/p/aFmsL3WA-L package main import ( "fmt" ) func main() { type a struct { Hello string } type b struct { Hello string } type c struct { a b } herp := c{a{"hello"},b{"world"}} fmt.Println(herp.Hello) } This doesn't compile. There is no herp.Hello. Therefore json.Marshal does not marshal one. Status changed to WorkingAsIntended. |
Comment 6 by trey@jellolabs.com: Don't you think that json.Marshal should return a runtime error similar to the one given by the compiler in your example? |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by trey@jellolabs.com:
The text was updated successfully, but these errors were encountered: