Open
Description
~/go/src/github.com/dgryski/bug/anynil $ tinygo run main.go
false
~/go/src/github.com/dgryski/bug/anynil $ go run main.go
true
~/go/src/github.com/dgryski/bug/anynil $ cat main.go
package main
import (
"encoding/json"
"reflect"
)
type nilJSONMarshaler string
func (nm *nilJSONMarshaler) MarshalJSON() ([]byte, error) {
// behavior differs from upstream Go
return json.Marshal("0zenil0:" + string(*nm))
// behaviour matches upstream Go
// return nil, nil
}
var _ = json.Marshaler(nil)
type Marshaler interface {
MarshalJSON() ([]byte, error)
}
var marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
func main() {
v := struct{ M Marshaler }{(*nilJSONMarshaler)(nil)}
f0 := reflect.TypeOf(v).Field(0).Type
println(f0.Implements(marshalerType))
}