-
Notifications
You must be signed in to change notification settings - Fork 18k
types2, go/types: pseudo-specialization sometimes works, but not really #47419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Unless I'm mistaken, this code:
Is equivalent to:
It compiles because you've used the name If I write:
The error message is The |
Interesting. So type parameters in type definitions are universally quantified, but type indices (?) in method definitions act more like existentials. This is somewhat strange because type parameters in non-method functions are universals. |
A definition like func (b Bar[int]) bar() int { return b.v } just means that for the body of the method, the type parameter is named func (b Bar[MyTypeParameterName]) bar() MyTypeParameterName { return b.v } Remember that in Go Similarly, this is valid Go; func F(int string) string { return int } |
From the design document:
On latest commit 37d2219 of dev.typeparams branch this code compiles just fine:
Is this an instance of specialization? This is the sole instance of the code, and it "works" (but see
baz
below). Should it be accepted?Regardless, the following doesn't work:
it fails with
cannot use 42 (untyped int constant) as int value in return statement
, which is a rather confusing error message.Interestingly enough, this also doesn't work:
the error in this case is
invalid operation: operator + not defined on b.v (variable of type parameter type int)
.The text was updated successfully, but these errors were encountered: