Skip to content

cmd/compile: error in Go 1.23.0 with generics, type aliases and indexing #68903

Closed
@phynes-sensiblecode

Description

@phynes-sensiblecode

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.

Metadata

Metadata

Assignees

Labels

NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions