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 upgo/types: include import path in type error messages #35895
Comments
This comment has been minimized.
This comment has been minimized.
Same issue, but for runtime errors: #11634 |
This comment has been minimized.
This comment has been minimized.
/cc @griesemer per owners. |
This comment has been minimized.
This comment has been minimized.
Marking tentatively for 1.14 since this only affects an error message. |
This comment has been minimized.
This comment has been minimized.
Change https://golang.org/cl/209578 mentions this issue: |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
/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. |
This comment has been minimized.
This comment has been minimized.
Note that the compiler only prints the full import path when it sees ambiguity (same package name in multiple imports, I think). |
This comment has been minimized.
This comment has been minimized.
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 |
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?