Closed
Description
Go version
go1.23.0
Output of go env
in your module/workspace:
Can be seen in Go Playground
What did you do?
package main
import "fmt"
type A = map[string]interface{}
func m[T ~A](a interface{}) {
fmt.Println(a.(T)["key"])
}
func main() {
b := A{"key": "value"}
m[A](b)
}
See: https://go.dev/play/p/cFkeJ6ppEBk
What did you see happen?
This compiler error is seen on Go 1.23:
./prog.go:8:19: invalid operation: cannot index a.(T) (comma, ok expression of type T constrained by ~A)
The program compiles and runs as expected on Go 1.22.
If we move the type definition of A
to a different package then the code runs fine in Go 1.23:
https://go.dev/play/p/l_x4F190M3y
What did you expect to see?
There should be no compilation error.