-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
encoding/json: unmarshaler doesn't find UnmarshalJSON on embedded anonymous struct #46516
Comments
At first glance this seems like a bug, thanks. There have been many bugs in the past involving struct embedding, but after a quick search I don't think this is a duplicate. Want to try working on a fix with a test? cc @dsnet |
It's because The type of I think at the entrance of |
@googollee, thank you for your analysis. I agree with your assessment of why this isn't triggering. It seems that this is a bug that's existed for 10 years :) We could try fixing this for the Go1.18 release cycle, but I'm always wary of how fixing bugs breaks a number of users who already depend on the current behavior. |
We could always merge this early in the 1.18 cycle, and see if any users complain. I would hope that noone is depending on the existing inconsistent behavior - I've been wrong on that assumption before, but not always :) |
Change https://golang.org/cl/324469 mentions this issue: |
Removing the check of named structs looses the limitation. I think it should be fine with existing codes. I made a change with a unit test. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/Xlxih58rSdC
Outer1 unmarshalled and Outer2 failed.
What did you expect to see?
Outer2 unmarshalled as Outer1
What did you see instead?
The text was updated successfully, but these errors were encountered: