Both

type X int | string

and

type X interface int, string

Are meant to be a syntax sugar for:

type X interface {
 type int, string
}

It is not a sum type, but rather a generic type that needs to be 
instantiated before the use. That is why it cannot have a zero value:

var x X // error, X must be instantiated before the use

But i think one should not be able to write:

type X interface {
 type int
 String() string
}

But instead it must be something like this:

type X interface {
 type int, fmt.Stringer
}

Or:

type X interface int, fmt.Stringer

Or:

type X interface int, interface{String() string}

https://go2goplay.golang.org/p/fNqNeDyM3R9

I do understand that this is kinda the same case like x.Name (complex 
literals in contracts), but in my opinion it would bit a bit more 
consistent syntax, wouldn't it?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ffd67b7b-3f95-46eb-b826-c1b003fde2cco%40googlegroups.com.

Reply via email to