]> Cypherpunks repositories - gostls13.git/commit
go/importer: associate exported field and interface methods with correct package
authorRobert Griesemer <gri@golang.org>
Wed, 13 Jan 2016 01:02:32 +0000 (17:02 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 13 Jan 2016 18:34:14 +0000 (18:34 +0000)
commit756088549f764b7b75d4605d69cc1a187749fc6a
tree7a47e43b77253375d01e506a2860d0b026575285
parent9efc46f1cbedc8971c99a49b0c2736fece13135e
go/importer: associate exported field and interface methods with correct package

In gc export data, exported struct field and interface method names appear
in unqualified form (i.e., w/o package name). The (gc)importer assumed that
unqualified exported names automatically belong to the package being imported.
This is not the case if the field or method belongs to a struct or interface
that was declared in another package and re-exported.

The issue becomes visible if a type T (say an interface with a method M)
is declared in a package A, indirectly re-exported by a package B (which
imports A), and then imported in C. If C imports both A and B, if A is
imported before B, T.M gets associated with the correct package A. If B
is imported before A, T.M appears to be exported by B (even though T itself
is correctly marked as coming from A). If T.M is imported again via the
import of A if gets dropped (as it should) because it was imported already.

The fix is to pass down the parent package when we parse imported types
so that the importer can use the correct package when creating fields
and methods.

Fixes #13898.

Change-Id: I7ec2ee2dda15859c582b65db221c3841899776e1
Reviewed-on: https://go-review.googlesource.com/18549
Reviewed-by: Alan Donovan <adonovan@google.com>
src/go/internal/gcimporter/gcimporter.go
src/go/internal/gcimporter/gcimporter_test.go
src/go/types/issues_test.go