Skip to content

Commit

Permalink
Merge pull request #1397 from cogentcore/fieldbypath
Browse files Browse the repository at this point in the history
fix for FieldByPath
  • Loading branch information
kkoreilly authored Dec 23, 2024
2 parents d797b66 + b26079b commit ffedcac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions base/reflectx/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func FieldByPath(s reflect.Value, fieldPath string) (reflect.Value, error) {
}
sv = fv
}
return sv.Addr(), nil
return sv, nil
}

// CopyFields copies the named fields from src struct into dest struct.
Expand Down Expand Up @@ -299,7 +299,7 @@ func SetFieldsFromMap(obj any, vals map[string]any) error {
if err != nil {
errs = append(errs, err)
}
err = SetRobust(fld.Interface(), v)
err = SetRobust(PointerValue(fld).Interface(), v)
if err != nil {
err = errors.Log(fmt.Errorf("SetFieldsFromMap: was not able to apply value: %v to field: %s", v, k))
errs = append(errs, err)
Expand Down
4 changes: 2 additions & 2 deletions base/reflectx/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func TestFieldByPath(t *testing.T) {
spv := reflect.ValueOf(sp)
fv, err := FieldByPath(spv, "Pet.Age")
assert.NoError(t, err)
assert.Equal(t, 7, fv.Elem().Interface())
assert.Equal(t, 7, fv.Interface())
fv, err = FieldByPath(spv, "Pet.Name")
assert.NoError(t, err)
assert.Equal(t, "Pet Gopher", fv.Elem().Interface())
assert.Equal(t, "Pet Gopher", fv.Interface())
fv, err = FieldByPath(spv, "Pet.Ages")
assert.Error(t, err)
fv, err = FieldByPath(spv, "Pets.Age")
Expand Down

0 comments on commit ffedcac

Please sign in to comment.