Skip to content

BigDecimal#dup causes Index 0 out of bounds for length 0 (ArrayIndexOutOfBoundsException) #1680

@deepj

Description

@deepj

It would return frozen instance and not cause the error above. Yes, I know about (ruby/bigdecimal#93 and https://bugs.ruby-lang.org/issues/13984)

The problem lies in this Rails test https://github.com/rails/rails/blob/6-0-stable/activesupport/test/core_ext/object/duplicable_test.rb#L26

truffleruby 1.0.0-rc17-dev-22c6a1c1, like ruby 2.6.2, GraalVM CE Native [x86_64-darwin]

To reproduce:

require 'bigdecimal'
BigDecimal('0.4').dup

Error:

Traceback (most recent call last):
        4: from ~/.rubies/truffleruby-1.0.0-nightly/bin/irb:31:in `<main>'
        3: from (irb):4
        2: from (irb):4:in `dup'
        1: from (irb):4:in `__allocate__'
RuntimeError (Index 0 out of bounds for length 0 (ArrayIndexOutOfBoundsException))
	from com.oracle.truffle.object.ShapeImpl$DynamicObjectFactoryImpl.newInstance(ShapeImpl.java:1058)
	from org.truffleruby.language.objects.AllocateObjectNode.allocate(AllocateObjectNode.java:150)
	from org.truffleruby.language.objects.AllocateObjectNode.allocateCached(AllocateObjectNode.java:69)
	from org.truffleruby.language.objects.AllocateObjectNodeGen.executeAndSpecialize(AllocateObjectNodeGen.java:135)
	from org.truffleruby.language.objects.AllocateObjectNodeGen.executeAllocate(AllocateObjectNodeGen.java:83)
	from org.truffleruby.language.objects.AllocateObjectNode.allocate(AllocateObjectNode.java:46)
	from org.truffleruby.core.basicobject.BasicObjectNodes$AllocateNode.allocate(BasicObjectNodes.java:486)
	from org.truffleruby.core.basicobject.BasicObjectNodesFactory$AllocateNodeFactory$AllocateNodeGen.executeAndSpecialize(BasicObjectNodesFactory.java:1556)
	from org.truffleruby.core.basicobject.BasicObjectNodesFactory$AllocateNodeFactory$AllocateNodeGen.execute(BasicObjectNodesFactory.java:1548)
	from org.truffleruby.l

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions