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

Discrepancy with MRI: assigning to a sequence of variables #1347

Closed
philipmw opened this issue Dec 18, 2013 · 3 comments
Closed

Discrepancy with MRI: assigning to a sequence of variables #1347

philipmw opened this issue Dec 18, 2013 · 3 comments
Milestone

Comments

@philipmw
Copy link

Simplest test case:

a,b = nil

Output of JRuby 1.7.9: => [nil]
Output of MRI 1.8.7 and 2.0.0p247: => nil

Some consequences:

  • Code executes differently between JRuby and MRI:
case
  when (a,b = function_returning_nil())
    puts "jruby"
  else
    puts "mri"
end

(Thanks to @luisantonioa for helping find the simplest test case for issue.)

EDIT: Moved a parser issue originally reported in this bug to #1353.

@headius
Copy link
Member

headius commented Dec 19, 2013

I think this is the first ever bug report I've seen that depends on the return value of a multiple assignment. Kudos :-)

The multiple assignment difference is indeed a bug. I confirmed that a,b = nil also returns nil in Ruby 1.9.3. Your test case shows where it can actually cause a problem.

The SyntaxError is a bit more confusing and is unrelated to the handling of the nil RHS.

MRI 1.8.7, 1.9.3, 2.0.0, and 2.1.0 all produce the SyntaxError in IRB but not when running the code directly (they warn instead of erroring).

JRuby in 1.8 mode produces the SyntaxError in IRB and when running the code directly. JRuby in 1.9 mode does not produce the error or the warning in either IRB or when running the code directly. JRuby master (2.1 mode only) behaves the same as JRuby in 1.9 mode.

I'm going to move your SyntaxError issue to a separate bug. It seems pretty trivial and may not be worth fixing, since JRuby actually seems more correct than MRI when JRuby runs in 1.9 and 2.1 modes.

@headius
Copy link
Member

headius commented Dec 19, 2013

Worth noting that the new runtime for JRuby 9000 does handle this masgn correctly:

$ jruby -X-CIR blah.rb
mri

@headius headius modified the milestones: JRuby 1.7.12, JRuby 1.7.10 Feb 21, 2014
@enebo enebo modified the milestones: JRuby 1.7.13, JRuby 1.7.12 Apr 15, 2014
@enebo enebo modified the milestones: JRuby 1.7.14, JRuby 1.7.13 Jun 24, 2014
@enebo enebo modified the milestones: JRuby 1.7.14, JRuby 1.7.15 Aug 27, 2014
@enebo enebo modified the milestones: Won't Fix, JRuby 1.7.15 Feb 17, 2017
@enebo
Copy link
Member

enebo commented Feb 17, 2017

This works in 9k and we will never fix this in 1.7.x as it is winding down (only one last point release until EOL)....resolving as WONTFIX.

@enebo enebo closed this as completed Feb 17, 2017
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

3 participants