Golang interface union type parameter

1,450 views
Skip to first unread message

Richiise Nugraha

unread,
Mar 12, 2022, 11:57:35 AM3/12/22
to golang-nuts
Is Go type parameter supports interface union? 

My case
type MessageSpec interface { MessageA | MessageB }
type MessageA interface { ID() uint64 }
type MessageB interface { Uid() uint64 }

but got compile error:
./prog.go:14:2: cannot use main.MessageA in union (main.MessageA contains methods) ./prog.go:14:13: cannot use main.MessageB in union (main.MessageB contains methods)


There's example 
> type Stringish interface { string | fmt.Stringer }

but it also throwing error
./prog.go:19:11: cannot use fmt.Stringer in union (fmt.Stringer contains methods)

Is this a bug? i know my case is not the same thing as like the one i referenced from the proposal
but it is throwing the same error.
Thanks

Richiise Nugraha

unread,
Mar 12, 2022, 12:14:22 PM3/12/22
to golang-nuts

Richiise Nugraha

unread,
Mar 12, 2022, 12:22:53 PM3/12/22
to golang-nuts
Reply all
Reply to author
Forward
0 new messages