]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: include pkgPath on all struct types
authorDavid Crawshaw <crawshaw@golang.org>
Wed, 30 Mar 2016 15:15:01 +0000 (11:15 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Thu, 31 Mar 2016 20:11:39 +0000 (20:11 +0000)
Fixes #15026.

Change-Id: I61ed71152b99973270d79264d1e8f466f7343c02
Reviewed-on: https://go-review.googlesource.com/21286
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/compile/internal/gc/reflect.go
src/reflect/all_test.go
src/reflect/export_test.go

index da7bd56afe4ffb4d8ca16d2eb0f8f995b8c0abb7..4bad490a64164aa860eed3a86001688a4a7685cc 100644 (file)
@@ -1277,7 +1277,7 @@ ok:
                }
 
                ot = dcommontype(s, ot, t)
-               var pkg *Pkg
+               pkg := localpkg
                if t.Sym != nil {
                        pkg = t.Sym.Pkg
                }
index ebd352ca46ac1d47bfd3590ae1ac3d16c2e04a86..0ce6588e988e17d629e56d6bdf1961c68e7b1922 100644 (file)
@@ -2321,6 +2321,33 @@ func TestImportPath(t *testing.T) {
        }
 }
 
+func TestFieldPkgPath(t *testing.T) {
+       typ := TypeOf(struct {
+               Exported   string
+               unexported string
+               OtherPkgFields
+       }{})
+       for _, test := range []struct {
+               index     []int
+               pkgPath   string
+               anonymous bool
+       }{
+               {[]int{0}, "", false},             // Exported
+               {[]int{1}, "reflect_test", false}, // unexported
+               {[]int{2}, "", true},              // OtherPkgFields
+               {[]int{2, 0}, "", false},          // OtherExported
+               {[]int{2, 1}, "reflect", false},   // otherUnexported
+       } {
+               f := typ.FieldByIndex(test.index)
+               if got, want := f.PkgPath, test.pkgPath; got != want {
+                       t.Errorf("Field(%d).PkgPath = %q, want %q", test.index, got, want)
+               }
+               if got, want := f.Anonymous, test.anonymous; got != want {
+                       t.Errorf("Field(%d).Anonymous = %v, want %v", test.index, got, want)
+               }
+       }
+}
+
 func TestVariadicType(t *testing.T) {
        // Test example from Type documentation.
        var f func(x int, y ...float64)
index 9db6967ffa6d242fea13d6b262eb0a824bc1a6b4..ddc64b46be098dec4a8fe4b96866314c0724e730 100644 (file)
@@ -94,3 +94,8 @@ func FirstMethodNameBytes(t Type) *byte {
        }
        return m.name.bytes
 }
+
+type OtherPkgFields struct {
+       OtherExported   int
+       otherUnexported int
+}