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

go/types: incorrect type in Info.Implicits map #21591

Closed
lvelden opened this issue Aug 24, 2017 · 4 comments
Closed

go/types: incorrect type in Info.Implicits map #21591

lvelden opened this issue Aug 24, 2017 · 4 comments
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. FrozenDueToAge
Milestone

Comments

@lvelden
Copy link

lvelden commented Aug 24, 2017

In this code I have a dot-import and I want to look up the respective type.Object:

https://play.golang.org/p/vJYe1kUJ0w (The importer doesn't work in the playground, so this has to be run locally)

The documentation for the Implicits map in go/types.Info (https://golang.org/pkg/go/types/#Info) says that an *ast.ImportSpec maps to a *PkgName for dot-imports, instead I get a *Func in the example above.

Running with go1.9rc2 on linux/amd64

@mvdan mvdan changed the title Incorrect type in types.Info.Implicits map go/types: incorrect type in Info.Implicits map Aug 24, 2017
@mvdan
Copy link
Member

mvdan commented Aug 24, 2017

CC @griesemer

@griesemer
Copy link
Contributor

Indeed. Definitively looks like a bug.

@griesemer griesemer added this to the Go1.10 milestone Aug 24, 2017
@griesemer griesemer self-assigned this Aug 24, 2017
@griesemer griesemer added the early-in-cycle A change that should be done early in the 3 month dev cycle. label Aug 24, 2017
@griesemer
Copy link
Contributor

Theres is an error in the documentation and the implementation:

  1. The documentation should not mention dot-imports for *ast.ImportSpec entries in the Implicits map because dot-imports are already explicitly covered by the Defs map (which will have an entry for the special identifier named ".").
  2. The implementation shouldn't add anything for *ast.ImportSpec nodes to the Implicits map. Right now it adds all the objects imported via the dot-import and it maps them all to the one corresponding *ast.ImportSpec. As a result, what is found in Implicits is simple the "last" exported object of that dot-imported package, and what is the "last" object depends on the (random) iteration order over the map of objects of the imported package scope.
    (Arguably, dot-imported objects are implicitly defined, but there's no mechanism that permits multiple objects to be associated with a single *ast.ImportSpec; and we're not going to add one.)

Fix forthcoming.

@gopherbot
Copy link

Change https://golang.org/cl/60672 mentions this issue: go/types: fix Info.Implicits entries

@golang golang locked and limited conversation to collaborators Sep 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. FrozenDueToAge
Projects
None yet
Development

No branches or pull requests

4 participants