Skip to content

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

@mvdan

Description

@mvdan
$ 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone 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