What version of Go are you using (go version)?
$ go version
go version devel go1.18-23adc139bf Fri Nov 12 14:56:58 2021 +0000 linux/amd64
Does this issue reproduce with the latest release?
Yes, the latest tip.
What did you do?
package main
func Split[T []byte|string](s T, x byte) (a, b T) {
var k = 0
for ; k < len(s); k++ {
if s[k] == x {
goto End
}
}
a = s
return
End:
return s[:k], s[k+1:] // invalid operation: cannot slice s (variable of type T constrained by []byte|string): T has no structural type
}
type MyByte byte
func Foo[T []byte|[]MyByte](s T) {
for range s {} // cannot range over s (variable of type T constrained by []byte|[]MyByte) (T has no structural type)
}
func Bar[T []byte|map[int]byte](s T) {
for range s {} // cannot range over s (variable of type T constrained by []byte|map[int]byte) (T has no structural type)
}
func Duk[T []byte|string](s T) {
for range s {} // cannot range over s (variable of type T constrained by []byte|string) (T has no structural type)
}
type Bytes []byte
func Zed[T []byte|Bytes](s T) {
for range s {} // okay
}
func main() {}
What did you expect to see?
Compiles okay.
What did you see instead?
Some functions don't compile.
The rule is too restricted, which will limit the use scope of type parameters.
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
Yes, the latest tip.
What did you do?
What did you expect to see?
Compiles okay.
What did you see instead?
Some functions don't compile.
The rule is too restricted, which will limit the use scope of type parameters.