Skip to content

generics: indexing operations don't work on pointers to constraints derived from arrays #52802

Closed
@DeedleFake

Description

@DeedleFake

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.

./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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions