-
Notifications
You must be signed in to change notification settings - Fork 570
Open
Labels
Milestone
Description
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.