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

Comments

Projects
None yet
6 participants
@gopherbot

gopherbot commented Oct 23, 2014

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

This comment has been minimized.

Contributor

ianlancetaylor commented Oct 23, 2014

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

@bradfitz bradfitz removed the release-go1.5 label Dec 16, 2014

@rsc rsc removed accepted labels Apr 14, 2015

@rsc rsc changed the title from cmd/gc: package type name collision with built-in types in compiler error messages to cmd/compile: package type name collision with built-in types in compiler error messages Jun 8, 2015

@rsc

This comment has been minimized.

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

This comment has been minimized.

Member

odeke-em commented Dec 23, 2017

I'll work on this for Go1.11.

@gopherbot

This comment has been minimized.

gopherbot commented Dec 30, 2017

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

@gopherbot

This comment has been minimized.

gopherbot commented Mar 20, 2018

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

@andybons andybons added the NeedsFix label Mar 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment