-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Labels
Milestone
Description
Environment
$ jruby -v jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 Java HotSpot(TM) 64-Bit Server VM 25.161-b12 on 1.8.0_161-b12 +jit [darwin-x86_64]
Also can be replicated on 9.1.17.0 and 1.7.27
$ uname -a Darwin [redacted] 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
Issue also present on Windows 7
C:\Users\Sean Mccarthy>jruby -v jruby 9.1.17.0 (2.3.3) 2018-04-20 d8b1ff9 Java HotSpot(TM) 64-Bit Server VM 25.181-b13 on 1.8.0_181-b13 +jit [mswin32-x86_64]
Expected Behavior
Here's a test case:
require 'bigdecimal'
class NullValue
def nil?
true
end
def coerce(other)
case other
when Numeric
[other, BigDecimal(0)]
end
end
def method_missing(method_name, *arguments, &block)
BigDecimal(0).send(method_name, *arguments, &block)
end
end
puts "Trying addition:"
puts BigDecimal(100) + NullValue.new
puts "Trying multiplication:"
puts BigDecimal(100) * NullValue.new
puts "Trying division:"
puts BigDecimal(100) / NullValue.new
puts "Trying subtraction:"
puts BigDecimal(100) - NullValue.new
Output from MRI/CRuby 2.3.x
$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [x86_64-darwin17]
$ ruby null_value.rb
Trying addition:
0.1E3
Trying multiplication:
0.0
Trying division:
Infinity
Trying subtraction:
0.1E3
Actual Behavior
$ ruby -v
jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 Java HotSpot(TM) 64-Bit Server VM 25.161-b12 on 1.8.0_161-b12 +jit [darwin-x86_64]
$ ruby null_value.rb
Trying addition:
0.1e3
Trying multiplication:
0.0
Trying division:
Infinity
Trying subtraction:
TypeError: NullValue can't be coerced into BigDecimal
- at org/jruby/ext/bigdecimal/RubyBigDecimal.java:1134
<main> at null_value.rb:27
Reactions are currently unavailable