You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import"fmt"typeSomeConstraint[T] interface{
Foo() T
}
funcBar[TSomeConstraint](valT) { // [T SomeConstraint[int]] works wellfmt.Println(val.Foo())
}
typeimplstruct{}
func (impl) Foo() int { return1337 }
funcmain() {
Bar(impl{})
}
Got the error: impl does not satisfy SomeConstraint(T) (missing method Foo).
How to solve it? Or, if problem is in the function declaration, we need a better error message.
The text was updated successfully, but these errors were encountered:
When you write just SomeConstraint as the constraint in Bar, it means SomeConstraint[T]. That means that any type argument A must have a method Foo() A. Your type impl does not have such a method. It has Foo() int, but it needs to have Foo() impl.
go2go playground:
Got the error:
impl does not satisfy SomeConstraint(T) (missing method Foo)
.How to solve it? Or, if problem is in the function declaration, we need a better error message.
The text was updated successfully, but these errors were encountered: