Skip to content

go/types: var declaration changes representation of its type (alias related) #66704

@adonovan

Description

@adonovan

This is a minimized repro of another gotypesalias=1 problem affecting the x/tools gcimporter.
The root cause is clearly in go/types (at b24ec88).

package types // "go/types"

func TestAliasProblem(t *testing.T) {
	t.Setenv("GODEBUG", "gotypesalias=1")
	const src = `package a

var x T[B] // <-- this causes the problem! deleting it causes type of B to be ok

type T[_ any] struct{}
type A T[B]
type B = T[A]
`
	fset := token.NewFileSet()
	f, err := parser.ParseFile(fset, "a.go", src, 0)
	if err != nil {
		t.Fatal(err)
	}
	pkg, err := new(Config).Check("a", fset, []*ast.File{f}, nil)
	if err != nil {
		t.Fatal(err)
	}

	B := pkg.Scope().Lookup("B")
	t.Error(Unalias(B.Type())) // "invalid type" if var x is present, "a.T[a.A]" otherwise
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions