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 can not be copied #2868

Closed
gazay opened this issue Apr 22, 2015 · 3 comments
Closed

BigDecimal can not be copied #2868

gazay opened this issue Apr 22, 2015 · 3 comments

Comments

@gazay
Copy link
Contributor

@gazay gazay commented Apr 22, 2015

bug from rails tests

Missed initialize_copy for BigDecimal.

require 'bigdecimal'
BigDecimal.new(1).dup

MRI 2.2.2 output:

#<BigDecimal:7fdd1d01c910,'0.1E1',9(27)>

Jruby output:

TypeError: can't copy BigDecimal
    from org/jruby/RubyNumeric.java:584:in `initialize_copy'
    from org/jruby/RubyKernel.java:1883:in `initialize_dup'
    from org/jruby/RubyKernel.java:1913:in `dup'
    from (irb):8:in `<eval>'
    from org/jruby/RubyKernel.java:1005:in `eval'
    from org/jruby/RubyKernel.java:1315:in `loop'
    from org/jruby/RubyKernel.java:1125:in `catch'
    from org/jruby/RubyKernel.java:1125:in `catch'
    from /Users/alex/code/opensource/jruby/bin/irb:13:in `<top>'

Failing test in ActiveSupport:
https://github.com/rails/rails/blob/master/activesupport/test/core_ext/object/duplicable_test.rb#L21
This code testing Object extension here: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/duplicable.rb#L81

Backtrace:

DuplicableTest#test_duplicable:
TypeError: can't copy BigDecimal
    org/jruby/RubyNumeric.java:584:in `initialize_copy'
    org/jruby/RubyKernel.java:1883:in `initialize_dup'
    org/jruby/RubyKernel.java:1913:in `dup'
    rails/activesupport/test/core_ext/object/duplicable_test.rb:22:in `block in test_duplicable'
    rails/activesupport/lib/active_support/test_case.rb:82:in `assert_nothing_raised'
    rails/activesupport/test/core_ext/object/duplicable_test.rb:22:in `block in test_duplicable'
    org/jruby/RubyArray.java:1571:in `each'
    rails/activesupport/test/core_ext/object/duplicable_test.rb:20:in `test_duplicable'

Re-run test from activesupport directory with: ruby -w -Itest test/core_ext/object/duplicable_test.rb -n test_duplicable

@headius headius added this to the 9.0.0.0.rc1 milestone Apr 22, 2015
@headius
Copy link
Member

@headius headius commented Apr 22, 2015

Could you include the Rails test failure on these issues too? That will let us track it back to an original test for confirmation.

@gazay
Copy link
Contributor Author

@gazay gazay commented Apr 22, 2015

updated

@headius
Copy link
Member

@headius headius commented Apr 29, 2015

Looks like this was changed in MRI around 2011. They eliminated the custom .new and replaced it with a standard allocate+initialize: ruby/ruby@f9a4d57

The same flip in JRuby should not be too difficult.

@enebo enebo closed this in 003c47a May 1, 2015
enebo added a commit that referenced this issue May 1, 2015
Implementation of initialize_copy for BigDecimal (fix #2868)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants