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

runtime: new "types from different packages" messages is not always true #26094

Closed
rsc opened this issue Jun 27, 2018 · 2 comments
Closed

runtime: new "types from different packages" messages is not always true #26094

rsc opened this issue Jun 27, 2018 · 2 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jun 27, 2018

CL 116255 added an extra message to type assertion failures, so that under certain conditions they look like:

panic: interface conversion: interface {} is modfetch.cachedInfo, not modfetch.cachedInfo (types from different packages)

This confused me for a little while: I am working in golang.org/x/vgo/vendor/cmd/go/internal/modfetch and the only other modfetch that seemed plausible would be the cmd/go/internal/modfetch from the standard library. For a minute I wondered how the build could possibly have crossed the two package trees. But in fact in my crash the types in question are from the same package: the message is incorrect. I had originally declared the same type in two functions, and then when I realized one might leak into the other, I made a global, but I forgot to delete one of the function-scoped types.

Here is an equivalent reproduction case:

$ cat /tmp/x.go
package main

var X interface{}

type T struct{}

func F() {
	type T struct{}
	X = T{}
}

func G() {
	type T struct{}
	_ = X.(T)
}

func main() {
	F()
	G()
}
$ go run /tmp/x.go
panic: interface conversion: interface {} is main.T, not main.T (types from different packages)

goroutine 1 [running]:
main.G()
	/tmp/x.go:14 +0x54
main.main()
	/tmp/x.go:19 +0x25
exit status 2
$ 

Can we do something in the check to detect types from the same package but different scopes and change the message to "types from different scopes"? I suppose we could fall back to "types from different scopes or packages" but it would be more helpful if the message can be precise (without being incorrect).

The global type T is unused in the test program, but you could delete either the one in F or the one in G and have a perhaps different test case also worth checking.

/cc @griesemer @randall77

@rsc rsc added this to the Go1.11 milestone Jun 27, 2018
@griesemer
Copy link
Contributor

We could always say "types from different scopes" as that would also apply to them being from different packages.

@gopherbot
Copy link

Change https://golang.org/cl/123395 mentions this issue: runtime: don't say "different packages" if they may not be different

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 11, 2018
@golang golang locked and limited conversation to collaborators Jul 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants