-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
Description
This does not compile:
package p
type a1 [16]byte
type a2 [32]byte
type A interface {
a1 | a2
}
func elem0[T A](t *T) *byte {
return &t[0]
}
Error: ./x.go:11:10: invalid operation: cannot index t (variable of type *T)
This shows up in practice if you want to embed an array in a generic struct to avoid extra indirection/allocs, like this:
type S struct {
// other fields
arr A
}
but pass pointers to the array around internally to avoid making lots of copies of it (particularly as the array gets large).
The equivalent non-generic code compiles:
func elem0concrete(t *a1) *byte {
return &t[0]
}
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.