Skip to content

Commit 2e968f2

Browse files
committed
Fix array/map comparison when they have different sizes/keys
1 parent 8653d4c commit 2e968f2

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

spec/e2e/operator/equals.lit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ println(0 == "0") # expect: false
2020

2121
# compound types
2222
println([] == []) # expect: true
23+
println([1] == []) # expect: false
2324
println([1, "foo"] == [1, "foo"]) # expect: true
2425
println([1, "foo"] == ["foo", 1]) # expect: false
2526

src/lit/interpreter.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ module Lit
431431

432432
if a.is_a?(LitArray)
433433
return false if !b.is_a?(LitArray)
434-
return a.elements.each_with_index.all? { |value, i| equal?(value, b[i], token) }
434+
return a.elements.each_with_index.all? { |value, i| equal?(value, b.elements[i]?, token) }
435435
end
436436
if a.is_a?(LitMap)
437437
return false if !b.is_a?(LitMap)
438-
return a.elements.each_with_index.all? { |(key, value), i| equal?(value, b.elements[key], token) }
438+
return a.elements.each_with_index.all? { |(key, value), i| equal?(value, b.elements[key]?, token) }
439439
end
440440

441441
if a.is_a?(Instance) && (instance_eq = a.as(Instance).get_method(token.with_lexeme(BINARY_OP_TO_METHOD[:==])))

0 commit comments

Comments
 (0)