Skip to content

Commit 97e8c70

Browse files
MadiZzMadis-Siim Rull
andauthored
Make Hash comparison with integer raise Dentaku::ArgumentError instead of TypeError (#324)
Co-authored-by: Madis-Siim Rull <madis-siim@fintech-market.com>
1 parent 1db6b79 commit 97e8c70

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/dentaku/ast/comparators.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def value(context = {})
2020
r = validate_value(cast(right.value(context)))
2121

2222
l.public_send(operator, r)
23-
rescue ::ArgumentError => e
23+
rescue ::ArgumentError, ::TypeError => e
2424
raise Dentaku::ArgumentError.for(:incompatible_type, value: r, for: l.class), e.message
2525
end
2626

spec/calculator_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
expect { calculator.evaluate!('"foo" & "bar"') }.to raise_error(Dentaku::ArgumentError)
131131
expect { calculator.evaluate!('1.0 & "bar"') }.to raise_error(Dentaku::ArgumentError)
132132
expect { calculator.evaluate!('1 & "bar"') }.to raise_error(Dentaku::ArgumentError)
133+
expect { calculator.evaluate!('data < 1', data: { a: 5 }) }.to raise_error(Dentaku::ArgumentError)
133134
end
134135

135136
it 'raises argument error if a function is called with incorrect arity' do

0 commit comments

Comments
 (0)