Go version
go version go1.22.4 darwin/arm64
Output of go env in your module/workspace:
What did you do?
Go's generics supports defining constraints on array sizes:
type commonBinaryLengths interface {
// footgun | address | hash | pubkey
~[]byte | ~[20]byte | ~[32]byte | [48]byte
}
However, creating constraints out of those in another dimension fails to infer:
type commonArrayLengths[U commonBinaryLengths] interface {
// footgun | roots
~[]U | ~[8192]U
}
Explicitly spoon feeding the compiler with the types will succeed in building the code, so it seems it's not a misuse of generics, simply a bug in the compiler's inference system:
https://go.dev/play/p/DdmLfxH5eaq
What did you see happen?
The inferred generic calls fail to compile whereas the spoon-fed ones build fine.
What did you expect to see?
I expect all lines to compile and run successfully.
Go version
go version go1.22.4 darwin/arm64
Output of
go envin your module/workspace:Doesn't matter.What did you do?
Go's generics supports defining constraints on array sizes:
However, creating constraints out of those in another dimension fails to infer:
Explicitly spoon feeding the compiler with the types will succeed in building the code, so it seems it's not a misuse of generics, simply a bug in the compiler's inference system:
https://go.dev/play/p/DdmLfxH5eaq
What did you see happen?
The inferred generic calls fail to compile whereas the spoon-fed ones build fine.
What did you expect to see?
I expect all lines to compile and run successfully.