1
0

ignore unaddressable fields

This commit is contained in:
Arpad Ryszka 2025-09-01 03:11:04 +02:00
parent 9a6db08a25
commit bcadfd8b71
2 changed files with 5 additions and 3 deletions

View File

@ -189,6 +189,10 @@ func fieldValues(v reflect.Value) []Field {
}
vfi := v.Field(i)
if tfi.Anonymous && !vfi.CanAddr() {
continue
}
vfi = unpackValue(vfi, pointer|iface|anytype)
switch {
case tfi.Anonymous:

View File

@ -252,9 +252,7 @@ func TestField(t *testing.T) {
v.Foo = 21
v.Bar = 42
f := bind.FieldValues(v)
if len(f) != 2 ||
f[0].Name() != "foo" || f[0].Value() != 21 ||
f[1].Name() != "bar" || f[1].Value() != 42 {
if len(f) != 1 || f[0].Name() != "bar" || f[0].Value() != 42 {
t.Fatal()
}
})