cmd/compile: fix and improve struct field reflect information

The previous logic was overly complicated, generated suboptimally
encoded struct type descriptors, and mishandled embeddings of
predeclared universal types.

Fixes #21122.
Fixes #21353.
Fixes #21696.
Fixes #21702.
Updates #21357.

Change-Id: If34761fa6dbe4af2af59dee501e7f30845320376
Reviewed-on: https://go-review.googlesource.com/60410
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Matthew Dempsky 2017-08-30 14:17:24 -07:00
parent 812b34efae
commit d349fa25df
4 changed files with 111 additions and 54 deletions

View file

@ -1216,10 +1216,7 @@ func (t *structType) Field(i int) (f StructField) {
f.Name = p.name.name()
f.Anonymous = p.anon()
if !p.name.isExported() {
f.PkgPath = p.name.pkgPath()
if f.PkgPath == "" {
f.PkgPath = t.pkgPath.name()
}
f.PkgPath = t.pkgPath.name()
}
if tag := p.name.tag(); tag != "" {
f.Tag = StructTag(tag)
@ -1677,6 +1674,9 @@ func haveIdenticalUnderlyingType(T, V *rtype, cmpTags bool) bool {
if len(t.fields) != len(v.fields) {
return false
}
if t.pkgPath.name() != v.pkgPath.name() {
return false
}
for i := range t.fields {
tf := &t.fields[i]
vf := &v.fields[i]
@ -1692,19 +1692,6 @@ func haveIdenticalUnderlyingType(T, V *rtype, cmpTags bool) bool {
if tf.offsetAnon != vf.offsetAnon {
return false
}
if !tf.name.isExported() {
tp := tf.name.pkgPath()
if tp == "" {
tp = t.pkgPath.name()
}
vp := vf.name.pkgPath()
if vp == "" {
vp = v.pkgPath.name()
}
if tp != vp {
return false
}
}
}
return true
}