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
go/types: include import path in type error messages #35895
Comments
Same issue, but for runtime errors: #11634 |
/cc @griesemer per owners. |
Marking tentatively for 1.14 since this only affects an error message. |
Change https://golang.org/cl/209578 mentions this issue: |
The fix is trivial (https://golang.org/cl/209578) but may have implications for client code that parses error messages. Also, we're currently in the 1.14 freeze and this may cause needless instability. Marking NeedsDecision for input from others. |
/cc @neild who worked on defining an internal policy related to that, which can be helpful when making decisions about changing error messages. I'm okay with either, but I think it makes sense to leave to 1.15, since it's not fixing an existing bug. |
Note that the compiler only prints the full import path when it sees ambiguity (same package name in multiple imports, I think). |
The relevant code for the compiler is in cmd/compile/internal/gc/fmt.go: // If the name was used by multiple packages, display the full path,
if s.Pkg.Name != "" && numImport[s.Pkg.Name] > 1 {
return fmt.Sprintf("%q.%s", s.Pkg.Path, s.Name)
}
return s.Pkg.Name + "." + s.Name |
The latest CL now matches the behavior of the compiler. |
Thanks for fixing this so quickly! This will eliminate a common issue for people learning Go in my class :) |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have the following Go source files (directory structure is relevant, so no play.golang.org link):
When using
go run demo.go
, I get:However, when using
go run ast.go
, I get:The latter message does not include the import path, only the package, and is hence very confusing especially for newcomers to the language: the two
*pkg1.Client
look exactly the same, so the error message looks non-sensical.The message is produced by the
go/types
package ingo/src/go/types/assignments.go
Line 64 in 8054b13
Note that some users in some environments might be exposed to error messages from
go/types
before they see the error message from the Go compiler because of how IDE integration works.Could we include the import path in the error messages produced by
go/types
as well please?The text was updated successfully, but these errors were encountered: