Skip to content

Commit

Permalink
merge.Override: Fix handling of dyn.NilValue
Browse files Browse the repository at this point in the history
  • Loading branch information
kanterov committed Jun 26, 2024
1 parent 2ec6abf commit 27e26d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions libs/dyn/merge/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions libs/dyn/merge/override_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down

0 comments on commit 27e26d6

Please sign in to comment.