Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigDecimal on the left while coercing doesn't have cases for multiplication and division #1598

Closed
deepj opened this issue Mar 6, 2019 · 3 comments
Assignees
Milestone

Comments

@deepj
Copy link

deepj commented Mar 6, 2019

I was surprised by this. I'd though this had been solved by #1533. Unfortunately, not yet for multiplication and division. I noticed when one test in Sequel tests failed in the latest TruffleRuby 1.0.0 RC 13. Ironically, on the same issue reported in #1507 => BigDecimal('1.0') * Sequel[:a][:y]

As an example to reproduce the issue, I use @janko's original code in #1507

require "bigdecimal"

class MyNumber
  def initialize(number)
    @number = number
  end

  def coerce(other)
    puts "called with #{other.inspect}"

    case other
    when Integer    then [other, @number]
    when BigDecimal then [other, BigDecimal.new(@number)]
    end
  end
end

1                 / MyNumber.new(2)
BigDecimal.new(1) / MyNumber.new(2)

1                 * MyNumber.new(2)
BigDecimal.new(1) * MyNumber.new(2)

Error:

bigdecimal.rb:19:in `*': Truffle doesn't have a case for the org.truffleruby.stdlib.bigdecimal.BigDecimalNodesFactory$MultOpNodeFactory$MultOpNodeGen node with values of type  BigDecimal(com.oracle.truffle.object.basic.DynamicObjectBasic) MyNumber(com.oracle.truffle.object.basic.DynamicObjectBasic) (TypeError)
	from bigdecimal.rb:19:in `<main>'
bigdecimal.rb:19:in `/': Truffle doesn't have a case for the org.truffleruby.stdlib.bigdecimal.BigDecimalNodesFactory$DivOpNodeFactory$DivOpNodeGen node with values of type  BigDecimal(com.oracle.truffle.object.basic.DynamicObjectBasic) MyNumber(com.oracle.truffle.object.basic.DynamicObjectBasic) (TypeError)
	from bigdecimal.rb:19:in `<main>'
@eregon
Copy link
Member

eregon commented Mar 6, 2019

Thanks for the report.
Sorry about that, we planned to fix other operations right after integrating #1533 (for which I didn't want to ask the author too much for a first contribution), but due to the OCA process which took much longer than expected and other more urgent tasks, this was forgotten.
I'll fix it.

@eregon
Copy link
Member

eregon commented Mar 6, 2019

An interesting thing to note:
BigDecimal#div(object, precision) doesn't try to coerce object on MRI, but BigDecimal#div(object) does.

@eregon
Copy link
Member

eregon commented Mar 7, 2019

I fixed this in 89e5a01, it will be in the next release.
I checked and the above example works identically on MRI and TruffleRuby now.
Thanks for the report!

@eregon eregon closed this as completed Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants