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

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

mvdan opened this issue Sep 23, 2020 · 5 comments

Comments

@mvdan
Copy link
Member

@mvdan 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 mvdan commented Sep 23, 2020

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

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Sep 23, 2020

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.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Sep 23, 2020

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

Loading

@cagedmantis cagedmantis added this to the Backlog milestone Sep 23, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 29, 2020

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

Loading

@gopherbot gopherbot closed this in 0e85fd7 Sep 29, 2020
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Sep 29, 2020

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

Loading

@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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants