Hi, I gave a talk with accompanying blog post about this exact topic, a while back: https://blog.merovius.de/posts/2024-01-05_constraining_complexity/
On Sat, 14 Mar 2026 at 03:52, Pierre Durand <[email protected]> wrote: > 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 > <https://groups.google.com/d/msgid/golang-nuts/375e05d7-151a-4cd9-bb60-bc617aa20bebn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEkBMfHPSSdC-SXp0M99vaS2SHbBDUAFBod-z9anJQCmR9fFeQ%40mail.gmail.com.
