Skip to content

go/types, types2: suboptimal error message for instantiated layout cycles #75022

@mrkfrmn

Description

@mrkfrmn

I was poking around in the type checker and discovered this:

type t[p any] struct {
	f p
}

type a t[a]

Which yields:

./prog.go:7:6: invalid recursive type a
	./prog.go:7:6: a refers to t
	./prog.go:7:8: t refers to a

Which seems a bit confusing as t is generic and makes no reference to a in its definition. I would have expected t[a] refers to a and such.

If we make the type argument an alias, we also do not mention the alias:

type t[p any] struct {
	f p
}

type b = a
type a t[b]
./prog.go:8:6: invalid recursive type a
	./prog.go:8:6: a refers to t
	./prog.go:8:8: t refers to a

I would have expected a t[b] refers to b and b refers to a.

Metadata

Metadata

Assignees

Labels

BadErrorMessageIssues related compiler error messages that should be better.BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions