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 [ TypeArgs
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 `Unmrshal
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 `AliastedDate.Time.UnmsrshalJSON
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.
ht
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 Marc
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,
despit