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
go version
$ go version go version go1.13.6 linux/amd64
Yes
go env
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/jackson/.cache/go-build" GOENV="/home/jackson/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/jackson/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build498302187=/tmp/go-build -gno-record-gcc-switches"
https://play.golang.org/p/DZoQ9ro3jv7 my parent struct inherits UnmarshalJSON(data []byte) error from the embedded struct
UnmarshalJSON(data []byte) error
https://github.com/golang/go/blob/master/src/encoding/json/decode.go#L492 in the indirect() function if u, ok := v.Interface().(Unmarshaler); ok { is true, but since the embedded struct is not allocated it will cause a nil pointer exception
indirect()
if u, ok := v.Interface().(Unmarshaler); ok {
encoding/json.(*decodeState).object(0xc0002ccd10, 0x5e9bc0, 0xc000132f98, 0x16, 0xc0002ccd38, 0xc0003abe7b) /usr/local/go/src/encoding/json/decode.go:667 +0x220b
&{&{}}
&{<nil>}
Unmarshal should allocate the embedded struct so that we can call UnmarshalJSON() this would only be relevant if there were only 1 embedded struct which implements UnmarshalJSON
The text was updated successfully, but these errors were encountered:
Thanks for the thoughtful issue report. This is a duplicate of #30148. Feel free to discuss there if you have more to contribute.
Sorry, something went wrong.
No branches or pull requests
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/DZoQ9ro3jv7
my parent struct inherits
UnmarshalJSON(data []byte) error
from the embedded structhttps://github.com/golang/go/blob/master/src/encoding/json/decode.go#L492
in the
indirect()
functionif u, ok := v.Interface().(Unmarshaler); ok {
is true, but since the embedded struct is not allocated it will cause a nil pointer exceptionWhat did you expect to see?
&{&{}}
What did you see instead?
&{<nil>}
Unmarshal should allocate the embedded struct so that we can call UnmarshalJSON()
this would only be relevant if there were only 1 embedded struct which implements UnmarshalJSON
The text was updated successfully, but these errors were encountered: