Skip to content

Commit

Permalink
Fix panic when comparing enum dict key in diff states
Browse files Browse the repository at this point in the history
Currently, dict key comparison uses nil *interpreter.Interpreter.
This causes a panic if dict key is enum type and interpreter is
needed to retrieve type info for comparison.

This commit passes non-nil Interpreter for dict key comparisons.
  • Loading branch information
fxamacker committed Jun 14, 2024
1 parent d32b10e commit 4de2204
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/util/ledger/migrations/cadence_value_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ func (dr *CadenceValueDiffReporter) diffCadenceDictionaryValue(
return true
})

onlyOldKeys, onlyNewKeys, sharedKeys := diffCadenceValues(oldKeys, newKeys)
onlyOldKeys, onlyNewKeys, sharedKeys := diffCadenceValues(vInterpreter, oldKeys, newKeys)

// Log keys only present in old dict value
if len(onlyOldKeys) > 0 {
Expand Down Expand Up @@ -915,7 +915,7 @@ func diff[T comparable](old, new []T) (onlyOld, onlyNew, shared []T) {
return
}

func diffCadenceValues(old, new []interpreter.Value) (onlyOld, onlyNew, shared []interpreter.Value) {
func diffCadenceValues(oldInterpreter *interpreter.Interpreter, old, new []interpreter.Value) (onlyOld, onlyNew, shared []interpreter.Value) {
onlyOld = make([]interpreter.Value, 0, len(old))
onlyNew = make([]interpreter.Value, 0, len(new))
shared = make([]interpreter.Value, 0, min(len(old), len(new)))
Expand All @@ -929,7 +929,7 @@ func diffCadenceValues(old, new []interpreter.Value) (onlyOld, onlyNew, shared [
foundShared := false

if ev, ok := o.(interpreter.EquatableValue); ok {
if ev.Equal(nil, interpreter.EmptyLocationRange, n) {
if ev.Equal(oldInterpreter, interpreter.EmptyLocationRange, n) {
foundShared = true
}
} else {
Expand Down

0 comments on commit 4de2204

Please sign in to comment.