You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's unclear yet whether this is a bug in the GopherJS compiler, or some customizations we've made either to reflect or encoding/json. I'll try to investigate when I have time. But consider the following code:
package main
import (
"encoding/json"
"fmt"
)
type Foo struct {
Foo string `json:"foo"`
}
func (f *Foo) UnmarshalJSON(p []byte) error {
t := struct {
Foo
UnmarshalJSON struct{}
}{}
return json.Unmarshal(p, &t)
}
func main() {
input := []byte(`{"foo":"a string"}`)
var f Foo
_ = json.Unmarshal(input, &f)
fmt.Println(f)
}
In the Go playground, it works as expected, with the UnmarshalJSON struct field shadowing the promoted UnmarshalJSON method on the embedded Foo type, and thus producing the output {}.
However, in GopherJS, it appears we attempt to execute the non-function, and produce a runtime panic: h.UnmarshalJSON is not a function.
The text was updated successfully, but these errors were encountered:
It's unclear yet whether this is a bug in the GopherJS compiler, or some customizations we've made either to
reflect
orencoding/json
. I'll try to investigate when I have time. But consider the following code:In the Go playground, it works as expected, with the
UnmarshalJSON
struct field shadowing the promotedUnmarshalJSON
method on the embeddedFoo
type, and thus producing the output{}
.However, in GopherJS, it appears we attempt to execute the non-function, and produce a runtime panic:
h.UnmarshalJSON is not a function
.The text was updated successfully, but these errors were encountered: