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
{{ message }}
Repository navigation
cmd/compile: type parameter unexpectedly does not implement constraint #56716
@ianlancetaylor suggested in that Google group thread that there is merit to record this as a bug, to be further looked at.
It felt interesting so I recorded it, despite not being the original submitter from the group (apologies if duplicate).
What did you expect to see?
Potentially the program successfully build
What did you see instead?
command-line-arguments
./test.go:22:41: []T does not implement Scalar|Vector ([]T missing in int | float32 | float64 | []int | []float32 | []float64)
./test.go:24:19: []T does not implement Scalar|Vector ([]T missing in int | float32 | float64 | []int | []float32 | []float64)
Create2 uses the type []T to instantiate a type parameter constrained by []int. Note that []T is not []int (even though T is constrained to be just int). When testing constraint satisfaction (which is interface implementation), we simply need to show that the type argument []T (a single type) is an element of the type set of interface{[]int}, which it is not. Hence the instantiation fails. (Note that this works.)
Activity
[-]affected/package: [/-][+]affected/package: generics[/+][-]affected/package: generics[/-][+]cmd/compile: type parameter unexpectedly does not implement constraint[/+]ianlancetaylor commentedon Nov 12, 2022
CC @griesemer @findleyr
griesemer commentedon Nov 14, 2022
This is working as expected.
Here's a simpler case reporting the same error:
Create2uses the type[]Tto instantiate a type parameter constrained by[]int. Note that[]Tis not[]int(even thoughTis constrained to be justint). When testing constraint satisfaction (which is interface implementation), we simply need to show that the type argument[]T(a single type) is an element of the type set ofinterface{[]int}, which it is not. Hence the instantiation fails. (Note that this works.)