Skip to content

BigDecimal can not be copied #2868

@gazay

Description

@gazay

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions