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

rsc opened this issue Jun 27, 2018 · 2 comments

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

rsc opened this issue Jun 27, 2018 · 2 comments


Copy link

@rsc 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 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() {
$ go run /tmp/x.go
panic: interface conversion: interface {} is main.T, not main.T (types from different packages)

goroutine 1 [running]:
	/tmp/x.go:14 +0x54
	/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
@rsc rsc added the release-blocker label Jun 27, 2018
Copy link

@griesemer griesemer commented Jun 28, 2018

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

Copy link

@gopherbot gopherbot commented Jul 11, 2018

Change mentions this issue: runtime: don't say "different packages" if they may not be different

@gopherbot gopherbot closed this in cda1947 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.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.