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
Note that in case 2, the input struct field says Anonymous false but the missing name triggers Anonymous true.
Note that in case 2, the input struct field has an empty PkgPath, but the missing name triggers setting PkgPath="runtime" (incorrectly, since the type is from package reflect_test).
I believe we should change StructOf so that if you have a struct type t, either StructOf([]StructField{t.Field(i)}) works and produces exactly the same field meaning or else it panics (if it's not implementable). If an input StructField is invalid (for example, it has no name), StructOf should panic.
I'm not sure what will break as a result of this; I hope not much, but the current situation is undocumented and contradicts the rest of the package, so a little breakage seems justifiable, and I can't - even with backwards compatibility hacks - make StructOf([]StructField{t.Field(i)}) work properly for embedded alias fields the way things are now.
Normally, if you have
then there are six reflect.StructFields:
However, these appear not to be the StructFields expected by reflect.StructOf.
This does not match the usual meaning of reflect.StructField, and it's undocumented.
I changed TestStructOfExportRules to print the input and output StructFields:
Note that in case 2, the input struct field says Anonymous false but the missing name triggers Anonymous true.
Note that in case 2, the input struct field has an empty PkgPath, but the missing name triggers setting PkgPath="runtime" (incorrectly, since the type is from package reflect_test).
I believe we should change StructOf so that if you have a struct type t, either StructOf([]StructField{t.Field(i)}) works and produces exactly the same field meaning or else it panics (if it's not implementable). If an input StructField is invalid (for example, it has no name), StructOf should panic.
I'm not sure what will break as a result of this; I hope not much, but the current situation is undocumented and contradicts the rest of the package, so a little breakage seems justifiable, and I can't - even with backwards compatibility hacks - make StructOf([]StructField{t.Field(i)}) work properly for embedded alias fields the way things are now.
For #18130.
/cc @sbinet
The text was updated successfully, but these errors were encountered: