mirror of
https://github.com/golang/go
synced 2024-11-23 05:50:05 -07:00
cmd/gc: make embedded, unexported fields read-only.
Fixes #7363. LGTM=gri R=gri, rsc, bradfitz CC=golang-codereviews https://golang.org/cl/66510044
This commit is contained in:
parent
15ec569ba9
commit
a8a7f18aea
@ -1127,7 +1127,8 @@ ok:
|
||||
ot = dgopkgpath(s, ot, t1->sym->pkg);
|
||||
} else {
|
||||
ot = dgostringptr(s, ot, nil);
|
||||
if(t1->type->sym != S && t1->type->sym->pkg == builtinpkg)
|
||||
if(t1->type->sym != S &&
|
||||
(t1->type->sym->pkg == builtinpkg || !exportname(t1->type->sym->name)))
|
||||
ot = dgopkgpath(s, ot, localpkg);
|
||||
else
|
||||
ot = dgostringptr(s, ot, nil);
|
||||
|
26
test/fixedbugs/issue7363.go
Normal file
26
test/fixedbugs/issue7363.go
Normal file
@ -0,0 +1,26 @@
|
||||
// run
|
||||
|
||||
// Copyright 2014 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.
|
||||
|
||||
// issue 7363: CanSet must return false for unexported embedded struct fields.
|
||||
|
||||
package main
|
||||
|
||||
import "reflect"
|
||||
|
||||
type a struct {
|
||||
}
|
||||
|
||||
type B struct {
|
||||
a
|
||||
}
|
||||
|
||||
func main() {
|
||||
b := &B{}
|
||||
v := reflect.ValueOf(b).Elem().Field(0)
|
||||
if v.CanSet() {
|
||||
panic("B.a is an unexported embedded struct field")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user