I'm trying to define a type constraint which is a union of interface.

type ReadStringer interface {
io.Reader | fmt.Stringer
}

Unfortunately the compiler rejects it:
cannot use io.Reader in union (io.Reader contains methods)
cannot use fmt.Stringer in union (fmt.Stringer contains methods)

I understand it's not possible, but I don't understand why.
Is there a logical problem ? Could it be supported in a future Go version ?

My goal is to define a function that accepts a parameter, then check at the 
execution time if it implements an interface or the other.
I could use "any", but it would be less safe.

Thank you.

-- 
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 visit 
https://groups.google.com/d/msgid/golang-nuts/375e05d7-151a-4cd9-bb60-bc617aa20bebn%40googlegroups.com.

Reply via email to