Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
Aha! That is what I was missing. Thank you. On Fri, May 20, 2022 at 7:37 AM 'Sean Liao' via golang-nuts < golang-nuts@googlegroups.com> wrote: > As explained above, `type AliasedDate Date` clears any methods you have > defined on `Date`. > But `Date` embeds `time.Time` which has its own

[go-nuts] Possible minor specification issues

2022-05-20 Thread Jan Mercl
I think there might be two small omissions in the EBNF grammar for Go 1.18: LiteralType = StructType | ArrayType | "[" "..." "]" ElementType | SliceType | MapType | TypeName . EmbeddedField = [ "*" ] TypeName . It seems to me that in both productions s/TypeName/TypeName [

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
Sorry about mixing up terms, however, my question still stands. encoding/json looks for the Marshaler/Unmarshaler interface convertibility, and in this case, the compiler thinks that the redeclared type does implement json.Unmarshaler. I extended my example to also do this test via reflection.

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread 'Sean Liao' via golang-nuts
As explained above, `type AliasedDate Date` clears any methods you have defined on `Date`. But `Date` embeds `time.Time` which has its own `UnmrshalJSON`, which now gets promoted. So `Date.UnmsrshalJSON` calls your `UnmsrshalJSON` `AliastedDate.UnmsrshalJSON` calls

[go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread Marcin Romaszewicz
Hi All, I've created a simple struct that wraps time.Time because I'd like to unmarshal it differently from JSON than the default. It works great. However, when I pass a type alias of that struct to json.Marshal or json.Unmarshal, the MarshalJSON and UnmarshalJSON functions aren't invoked,

Re: [go-nuts] encoding/json doesn't find marshal/unmarshal via type aliases

2022-05-20 Thread 'Axel Wagner' via golang-nuts
It's not an "aliased type". Type aliases take the form type A = B and they make the name A be interchangeable with the name B. What you have is a type declaration type A B which creates a fully new type, with a new method set, but the same underlying type as B. On Fri, May 20, 2022 at 9:28 AM