1
0
mirror of https://github.com/golang/go synced 2024-11-08 18:26:14 -07:00
go/test/fixedbugs/issue16616.dir/issue16616.go
David Crawshaw 14efaa0dc3 cmd/compile: qualify unexported fields of unnamed types
The compiler was canonicalizing unnamed types of the form

	struct { i int }

across packages, even though an unexported field i should not be
accessible from other packages.

The fix requires both qualifying the field name in the string used by
the compiler to distinguish the type, and ensuring the struct's pkgpath
is set in the rtype version of the data when the type being written is
not part of the localpkg.

Fixes #16616

Change-Id: Ibab160b8b5936dfa47b17dbfd48964a65586785b
Reviewed-on: https://go-review.googlesource.com/27791
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-08-26 11:46:15 +00:00

27 lines
666 B
Go

// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"reflect"
_ "./a"
"./b"
)
var V struct{ i int }
func main() {
if got := reflect.ValueOf(b.V).Type().Field(0).PkgPath; got != "b" {
panic(`PkgPath=` + got + ` for first field of b.V, want "b"`)
}
if got := reflect.ValueOf(V).Type().Field(0).PkgPath; got != "main" {
panic(`PkgPath=` + got + ` for first field of V, want "main"`)
}
if got := reflect.ValueOf(b.U).Type().Field(0).PkgPath; got != "b" {
panic(`PkgPath=` + got + ` for first field of b.U, want "b"`)
}
}