You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Happened to be working in cmd/compile/internal/gc/reflect.go and saw:
// Unnamed type. Grab the package from the first field, if any.
for _, f := range t.Fields().Slice() {
if f.Embedded != 0 {
continue
}
pkg = f.Sym.Pkg
break
}
I don't believe this is completely correct. There is no guarantee that the first non-embedded field will have a package. The commit message refers to
struct { i int }
which the code handles correctly, but I think the code still mishandles
struct { X int; i int }
because it will look at X, which has no Pkg, instead of at i, which does. It should probably continue the loop until it finds something with a pkg.
From what I can tell, the package we select there is just for a space optimization. Picking the wrong package means we waste space in the reflect type information tables (and thus should still be fixed), but I don't think it affects correctness at least.
@mdempsky the test in CL 27791, which introduced this code, is testing semantics observable via reflect and mentions #16616, so I don't think this is only about space usage.
It's not obvious to me that anything is wrong here. The f.Sym.Pkg field here is a compiler internal data structure. It's not the same as the reflect data. The fact that exported fields have no package in the reflect data is handled later, in dnameField.
Happened to be working in cmd/compile/internal/gc/reflect.go and saw:
I don't believe this is completely correct. There is no guarantee that the first non-embedded field will have a package. The commit message refers to
which the code handles correctly, but I think the code still mishandles
because it will look at X, which has no Pkg, instead of at i, which does. It should probably continue the loop until it finds something with a pkg.
/cc @crawshaw @griesemer @mdempsky
The text was updated successfully, but these errors were encountered: