Skip to content

go/types, types2: bad error message for cycles through type instantiation #74725

@mrkfrmn

Description

@mrkfrmn

I was doing a bit of testing with regards to cycles through instantiated types. If we type check the below:

type a = b[int]
type b[_ any] = a

We get the below error message:

./prog.go:3:6: invalid recursive type a
	./prog.go:3:6: a refers to b
	./prog.go:4:6: b refers to a
./prog.go:3:10: cannot use generic type b[_ any] without instantiation

The first reported error seems reasonable, but the second seems like an erroneous follow-on error. From the user's perspective, the type has been instantiated (b[int]) — it's a coincidence that a cycle error prevents said instantiation. Changing the definition of b to the below solves both errors.

type a = b[int]
type b[_ any] = int

I think it's reasonable to remove the second error here.

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.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions