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

cmd/compile: package type name collision with built-in types in compiler error messages #8983

Open
gopherbot opened this issue Oct 23, 2014 · 5 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@gopherbot
Copy link

by sedevelopers01:

v1.3.3

Thread on go-nuts:

    https://groups.google.com/forum/#!topic/golang-nuts/Ed3gU3EjbaI

Problem:

    When you define a package level "error" type (lower-case) it shadows the built-in error type and causes error messages like:

    > Cannot use errors.New("something wrong") (type error) as type error in return argument

Solutions proposed:

    Maybe the type name could be shown as "built in type error" in error messages, and the same for "built in type int".

    Or, on the other hand, maybe the locally defined type should be shown as "type foo.error" where foo is the package name in which it is defined.

    And then, why not both? That would make all error messages redundantly unambiguous.

    We've tried very hard to keep error messages concise. Perhaps we could just add the context where there is ambiguity.
@ianlancetaylor
Copy link
Contributor

Comment 1:

For the record, test case:
package p
import "errors"
type error int
func F() error {
    return errors.New("x")
}
foo.go:8: cannot use errors.New("x") (type error) as type error in return argument

Labels changed: added repo-main, release-go1.5.

Status changed to Accepted.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@rsc rsc removed accepted labels Apr 14, 2015
@rsc rsc changed the title cmd/gc: package type name collision with built-in types in compiler error messages cmd/compile: package type name collision with built-in types in compiler error messages Jun 8, 2015
@rsc
Copy link
Contributor

rsc commented Jun 29, 2015

Too late for Go 1.5.

@rsc rsc modified the milestones: Unplanned, Go1.5 Jun 29, 2015
@odeke-em odeke-em self-assigned this Dec 23, 2017
@odeke-em
Copy link
Member

I'll work on this for Go1.11.

@gopherbot
Copy link
Author

Change https://golang.org/cl/85715 mentions this issue: cmd/compile: disambiguate clashing types by package

@gopherbot
Copy link
Author

Change https://golang.org/cl/101675 mentions this issue: cmd/compile: disambiguate builtin types when shadowed

@andybons andybons added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants