An unexported field of a struct is not visible outside of the package
that defines it, so the package path is implicitly part of the
definition of any struct with an unexported field.
Change-Id: I17c6aac822bd0c24188ab8ba1cc406d6b5d82771
Reviewed-on: https://go-review.googlesource.com/32820
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
}
}
}
+
+func TestInaccessibleField(t *testing.T) {
+ var b Buffer
+ var localBuffer struct {
+ buf []byte
+ }
+ lv := ValueOf(&localBuffer).Elem()
+ rv := ValueOf(b)
+ shouldPanic(func() {
+ lv.Set(rv)
+ })
+}
func ResolveReflectName(s string) {
resolveReflectName(newName(s, "", "", false))
}
+
+type Buffer struct {
+ buf []byte
+}
if len(t.fields) != len(v.fields) {
return false
}
+ allExported := true
for i := range t.fields {
tf := &t.fields[i]
vf := &v.fields[i]
if tf.offset != vf.offset {
return false
}
+ allExported = allExported && tf.name.isExported()
+ }
+ if !allExported && t.pkgPath.name() != v.pkgPath.name() {
+ // An unexported field of a struct is not
+ // visible outside of the package that defines
+ // it, so the package path is implicitly part
+ // of the definition of any struct with an
+ // unexported field.
+ return false
}
return true
}