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
I tried to write a function that could copy between two pointers to types with an underlying array type.
It can be worked around by removing the array constraint and then manually converting when calling the function, such as in this example. This significantly hurts the ergonomics of the usage of the function, however.
What did you expect to see?
Successful compilation.
What did you see instead?
It claimed that range and indexing aren't allowed with the given constraints.
./prog.go:18:17: cannot range over out (variable of type *OA)
./prog.go:19:6: invalid operation: cannot index out (variable of type *OA)
./prog.go:19:16: invalid operation: cannot index in (variable of type *IA)
Go build failed.
The text was updated successfully, but these errors were encountered:
This is working as expected for the current spec and implementation. Indexing is only supported if the constraint of the type being indexed has a core type (https://go.dev/ref/spec#Core_types). We may try to address this in the future, but it's complicated because we have to think about a dependent type: a generic type that is not one of the type parameters (in your example the index result is one of the type parameters, but in a slightly different example it wouldn't be).
What version of Go are you using (
go version
)?Playground with
v=gotip
.Does this issue reproduce with the latest release?
Yes.
What did you do?
Playground Link
I tried to write a function that could copy between two pointers to types with an underlying array type.
It can be worked around by removing the array constraint and then manually converting when calling the function, such as in this example. This significantly hurts the ergonomics of the usage of the function, however.
What did you expect to see?
Successful compilation.
What did you see instead?
It claimed that
range
and indexing aren't allowed with the given constraints.The text was updated successfully, but these errors were encountered: