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

cmd/compile: "invalid recursive type" error is not as helpful as go/types #41575

Closed
mvdan opened this issue Sep 23, 2020 · 5 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented Sep 23, 2020

$ go version
go version devel +150bd4ffd4 Wed Sep 23 07:51:17 2020 +0000 linux/amd64
$ cat recursive.go 
package p

type T1 struct {
	f2 T2
}

type T2 struct {
	f1 T1
}
$ go build recursive.go 
# command-line-arguments
./recursive.go:7:6: invalid recursive type T2
$ go build -o gotype $(go env GOROOT)/src/go/types/gotype.go
$ ./gotype recursive.go 
recursive.go:3:6: illegal cycle in declaration of T1
recursive.go:3:6: 	T1 refers to
recursive.go:7:6: 	T2 refers to
recursive.go:3:6: 	T1

I had a cyclic type involving four types across three files, so I really did have to reach for gotype to understand what was going on. I think we should improve the compiler's typechecker to provide a similarly detailed error.

cc @griesemer @mdempsky @cuonglm

@mvdan
Copy link
Member Author

mvdan commented Sep 23, 2020

Also cc @findleyr given his recent work on go/types

@griesemer
Copy link
Contributor

We are seriously investigating using a revamped/adjusted go/types for the compiler in the future. The result should be consistent and better error messages from both, the compiler and the type checker.

@gopherbot
Copy link

Change https://golang.org/cl/256837 mentions this issue: cmd/compile: make invalid recursive type error for struct clearer

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 23, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Sep 23, 2020
@gopherbot
Copy link

Change https://golang.org/cl/258177 mentions this issue: cmd/compile: report type loop for invalid recursive types

@mdempsky
Copy link
Member

In Go 1.16, cmd/compile will report:

recursive.go:3:6: invalid recursive type T1
	recursive.go:3:6: T1 refers to
	recursive.go:7:6: T2 refers to
	recursive.go:3:6: T1

@golang golang locked and limited conversation to collaborators Sep 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

5 participants