[go2go] "interface contains type constraints"

2,048 views
Skip to first unread message

thwd

unread,
Dec 26, 2020, 4:21:53 PM12/26/20
to golang-nuts
My (short) code: 
https://go2goplay.golang.org/p/J4Ovyt-4xXN

The spec:

The errors:
prog.go2:7:30: interface contains type constraints (T, error)
prog.go2:19:32: interface contains type constraints (T, struct{})
prog.go2:10:13: interface contains type constraints (T, error)
prog.go2:15:13: interface contains type constraints (T, error)
prog.go2:22:13: interface contains type constraints (T, struct{})

What am I doing wrong?

Axel Wagner

unread,
Dec 26, 2020, 5:21:55 PM12/26/20
to thwd, golang-nuts
`Union[T, error]` is defined as

interface {
    type T, error
}

An interface containing a type-list can only be used as a constraint. However, you are using it as a type in several places.

--
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 golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6941a289-94b0-4bb1-99d2-c685652e46a8n%40googlegroups.com.

Axel Wagner

unread,
Dec 26, 2020, 5:27:51 PM12/26/20
to thwd, golang-nuts
PS: You might be interested in the discussion about whether or not to allow this in the future:
Reply all
Reply to author
Forward
0 new messages