Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types: specious "invalid recursive type" error? #60130

Open
mdempsky opened this issue May 11, 2023 · 3 comments
Open

go/types: specious "invalid recursive type" error? #60130

mdempsky opened this issue May 11, 2023 · 3 comments
Assignees
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mdempsky
Copy link
Member

Given:

package p

type s struct { i i }
type i interface { s | any }

go/types currently reports:

/tmp/y.go:3:6: invalid recursive type s
/tmp/y.go:3:6: 	s refers to
/tmp/y.go:4:6: 	i refers to
/tmp/y.go:3:6: 	s

Notably, changing the field type from i to *i makes the error go away. I don't see any fundamental reason why that should make a difference though.

Synthetic test case, constructed while trying to write additional test cases for #60117.

/cc @adonovan @findleyr @griesemer @ianlancetaylor

@mdempsky mdempsky added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 11, 2023
@adonovan
Copy link
Member

Seems pretty clearly disallowed by the current spec wording:

https://go.dev/ref/spec#Interface_types:

An interface type T may not embed a type element that is, contains, or embeds T, directly or indirectly.

// illegal: Bad3 may not embed a union containing Bad3
type Bad3 interface {
~int | ~string | Bad3
}

But I don't see the technical reason why the restriction is necessary in this case, as s.i is an ordinary named field.

@griesemer
Copy link
Contributor

The spec rule seems not sufficiently precisely spelled out. And there's probably a bug in the cycle check. Not urgent but added to my plate. Thanks for reporting.

@griesemer griesemer self-assigned this May 11, 2023
@griesemer griesemer added this to the Go1.21 milestone May 11, 2023
@griesemer griesemer modified the milestones: Go1.21, Go1.22 Jun 6, 2023
@griesemer
Copy link
Contributor

Too late for 1.21.

@griesemer griesemer modified the milestones: Go1.22, Go1.23 Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants