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: confusing error messages when package paths mismatch #16133

Closed
rogpeppe opened this issue Jun 21, 2016 · 6 comments
Closed

cmd/compile: confusing error messages when package paths mismatch #16133

rogpeppe opened this issue Jun 21, 2016 · 6 comments

Comments

@rogpeppe
Copy link
Contributor

rogpeppe commented Jun 21, 2016

Example error message:

./fakeapi_test.go:29: cannot use names.NewModelTag("dead-beef") (type names.ModelTag) as type names.ModelTag in field value

The error was actually that I'd imported the names package from the wrong path.
It would be nice if the error message could make that clearer - as it is, it
it confusing because both types look identical.

For example:

./fakeapi_test.go:29: cannot use names.NewModelTag("dead-beef") (type names.ModelTag) as type names.ModelTag in field value (package github.com/juju/names, not gopkg.in/juju/names.v2)

Another possibility might be to do general disambiguation when more than one
identical package name referring to a different path is used in the same error
message.

For example:

./fakeapi_test.go:52: cannot use "github.com/juju/names".NewModelTag("dead-beef") (type "github.com/juju/names".ModelTag) as type "gopkg.in/juju/names.v2".ModelTag in field value
@rogpeppe rogpeppe changed the title compiler: confusing error messages when package paths mismatch cmd/compile: confusing error messages when package paths mismatch Jun 21, 2016
@ianlancetaylor
Copy link
Contributor

There is actually code in symfmt in cmd/compile/internal/gc/fmt.go that is supposed to handle this (look for If the name was used by multiple packages). I don't know why it is not working for your example. What is your test case?

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 21, 2016
@rogpeppe
Copy link
Contributor Author

Here's a test case that can probably be reduced further.

==> ./b/b.go <==
package b
import "a2"

type T struct {
    X a.X
}

==> ./a1/a.go <==
package a

type X string

func NewX() X {
    return ""
}

==> ./a2/a.go <==
package a

type X string

func NewX() X {
    return ""
}

==> ./p/tst.go <==
package main
import (
    "a1"
    "b"
)

var _ = b.T{
    X: a.NewX(),
}

func main() {
}

Sample run:

% pwd
/tmp/d/src/p
% go install
# p
./tst.go:8: cannot use a.NewX() (type a.X) as type a.X in field value

@griesemer griesemer self-assigned this Jun 21, 2016
@griesemer
Copy link
Contributor

It looks like the respective code in the compiler doesn't trigger because numImport[s.Pkg.Name] is always 0 in this case. Possibly an error in the new importer. Investigating.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.7Maybe, Go1.8 Jun 21, 2016
@griesemer
Copy link
Contributor

Yes, this got lost in the move from the old textual importer to the new binary one. This is a 1.7 regression. We should probably fix it, the fix is simple; with it, the error message is:

tst.go:8: cannot use "/Users/gri/tmp/a".NewX() (type "/Users/gri/tmp/a".X) as type "/Users/gri/tmp/a2".X in field value

(I've compiled all packages in the tmp directory.)
CL coming later today.

@ianlancetaylor
Copy link
Contributor

@rogpeppe Thanks for the test case. This is in fact a regression since 1.6, so setting milestone to 1.7maybe.

1.6.2:

# issue16133
./tst.go:9: cannot use "issue16133/a1".NewX() (type "issue16133/a1".X) as type "issue16133/a2".X in field value

1.7beta2:

# issue16133
./tst.go:9: cannot use a.NewX() (type a.X) as type a.X in field value

@gopherbot
Copy link

CL https://golang.org/cl/24312 mentions this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants