Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
runtime: new "types from different packages" messages is not always true #26094
CL 116255 added an extra message to type assertion failures, so that under certain conditions they look like:
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:
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.