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
funcfoo[T~int]() T {
x:=42returnT(x) // OK
}
funcfoo2[T~int]() T {
x:=42returnint(x) // ERROR: cannot use int(x) (value of type int) as type T in return statement
}
funcmain() {}
What did you expect to see?
Compile pass.
What did you see instead?
Compile error.
The text was updated successfully, but these errors were encountered:
Sigh, sounds very limited. Though I noticed that we could:
funcfoo2[T~int]() T {
x:=42returnT(int(x)) // OK
}
But use cases like this still can't work:
package main
typeAstruct{}
func (aA) Foo() {}
typeBstruct{}
func (bB) Foo() {}
typeCinterface{ Foo() }
funcWant[TC]() *T {
varxTswitch (interface{})(x).(type) {
caseA:
return (*T)(&A{}) // cannot convert &A{} (value of type *A) to type *T: *A does not implement *T (type *T is pointer to interface, not interface)caseB:
return (*T)(&B{}) // cannot convert &B{} (value of type *B) to type *T: *B does not implement *T (type *T is pointer to interface, not interface)default:
panic("unknown")
}
}
funcmain() {
Want[A]()
Want[B]()
}
Does this issue reproduce with the latest release?
Yes
What did you do?
https://go.dev/play/p/pCzjLWAepvO?v=gotip
What did you expect to see?
Compile pass.
What did you see instead?
Compile error.
The text was updated successfully, but these errors were encountered: