merge.Override: Fix handling of dyn.NilValue (#1530)

## Changes
Fix handling of `dyn.NilValue` in `merge.Override` in case `dyn.Value`
has location

## Tests
Unit tests
This commit is contained in:
Gleb Kanterov 2024-06-27 11:47:58 +02:00 committed by GitHub
parent cdd6fe8cb9
commit dba6164a4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 8 deletions

View File

@ -30,10 +30,6 @@ func Override(leftRoot dyn.Value, rightRoot dyn.Value, visitor OverrideVisitor)
}
func override(basePath dyn.Path, left dyn.Value, right dyn.Value, visitor OverrideVisitor) (dyn.Value, error) {
if left == dyn.NilValue && right == dyn.NilValue {
return dyn.NilValue, nil
}
if left.Kind() != right.Kind() {
return visitor.VisitUpdate(basePath, left, right)
}
@ -98,9 +94,11 @@ func override(basePath dyn.Path, left dyn.Value, right dyn.Value, visitor Overri
} else {
return visitor.VisitUpdate(basePath, left, right)
}
case dyn.KindNil:
return left, nil
}
return dyn.InvalidValue, fmt.Errorf("unexpected kind %s", left.Kind())
return dyn.InvalidValue, fmt.Errorf("unexpected kind %s at %s", left.Kind(), basePath.String())
}
func overrideMapping(basePath dyn.Path, leftMapping dyn.Mapping, rightMapping dyn.Mapping, visitor OverrideVisitor) (dyn.Mapping, error) {

View File

@ -330,9 +330,9 @@ func TestOverride_Primitive(t *testing.T) {
{
name: "nil (not updated)",
state: visitorState{},
left: dyn.NilValue,
right: dyn.NilValue,
expected: dyn.NilValue,
left: dyn.NilValue.WithLocation(leftLocation),
right: dyn.NilValue.WithLocation(rightLocation),
expected: dyn.NilValue.WithLocation(leftLocation),
},
{
name: "nil (updated)",