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

dup on Range regression #3163

Closed
etehtsea opened this Issue Jul 22, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@etehtsea
Copy link
Contributor

etehtsea commented Jul 22, 2015

JRuby 9k final:

>> Range.new(0, 1000).dup
NameError: `initialize' called twice
    from org/jruby/RubyRange.java:247:in `initialize_copy'
    from org/jruby/RubyKernel.java:1860:in `initialize_dup'
    from org/jruby/RubyKernel.java:1898:in `dup'

JRuby 1.7.20.1:

>> Range.new(0,1000).dup
=> 0..1000

@enebo enebo added this to the JRuby 9.0.1.0 milestone Jul 22, 2015

@cheald

This comment has been minimized.

Copy link
Contributor

cheald commented Jul 22, 2015

This was broken in the course of fixing an MRI test:

def test_initialize_twice
  r = eval("1..2")
  assert_raise(NameError) { r.instance_eval { initialize 3, 4 } }
  assert_raise(NameError) { r.instance_eval { initialize_copy 3..4 } }
end

And apparently #dup calls initialize_copy. I'll get into the MRI source and figure out what it's doing differently.

cheald added a commit to cheald/jruby that referenced this issue Jul 22, 2015

Fix RubyRange#initialize_copy mistakenly erroring on #dup'ing a range.
…Closes jruby#3163

MRI checks if the EXCL flag is Qnil to see if the range has been initalized. This doesn't work
in Java because we use a boolean which can't have a nil value. Instead, introduce a new isInited
flag which is used to track the initialization state of the Range, which corrently permits #dup
while not permitting reinitialization of a Range.

@enebo enebo closed this in #3165 Jul 23, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.