-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/compile: type arguments for generic aliases are not checked against type parameter constraints #69576
Comments
As the error indicates, this is because you declared Changing your variable to be |
as mentioned above, type aliases don't allow you to relax type constraints. |
Think it should be reopened. (made the same mistake initially :) |
I'm not relaxing the constraint with the alias. Declaring an alias with the same constraint as the initial type constraint eliminates it. The code compiles, but should error out FMPV. |
This does look like a bug. The type alias permits type arguments that are not permitted by the constraint. |
It appears that we're not checking the constraints for alias type parameters at all. Simpler reproducer: package p
type A[P int] = struct{}
var _ A[string] // no error reported here Temp. work-around: write correct code... |
It seems to me that when checking var type, we stop immediately as long as we see typeparam. |
@cuonglm This is unrelated to var types. It also happens if we declare another type that depends on |
Change https://go.dev/cl/615275 mentions this issue: |
Go version
go version devel go1.24-c208b91395 Fri Sep 20 13:54:44 2024 +0000 X:aliastypeparams linux/amd64
Output of
go env
in your module/workspace:What did you do?
see in playground
What did you see happen?
The output is
main.T[string]{f:""}
What did you expect to see?
error
string does not satisfy int (string missing in int)
The text was updated successfully, but these errors were encountered: