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

Multiple assignment in conditionals possible #2433

Closed
endofunky opened this issue Jan 6, 2015 · 4 comments
Closed

Multiple assignment in conditionals possible #2433

endofunky opened this issue Jan 6, 2015 · 4 comments

Comments

@endofunky
Copy link

However, it shouldn't be, according to MRI.

Example:

foo = [1,2]

if (a, b = foo)
  puts a
  puts b
end

MRI:

% ruby ./t.rb
./t.rb:6: multiple assignment in conditional

JRuby 9k:

% ruby ./t.rb
1
2
@enebo
Copy link
Member

enebo commented Jan 6, 2015

Pretty amazing. We have always worked and MRI has always raised this error. @tobiassvn if you would like to go the extra mile you could open an issue at ruby-lang and ask if this should be made to work. I guess my only guess would be that this must always evaluate to true so it makes no sense to have it in a conditional? but they do not restrict other things so it may be worth raising?

It should not be very hard to detect an masgn in the ifexpr part of the AST if we do need to fix this.

@endofunky
Copy link
Author

It seems like it's already been discussed there. Quite recently actually:

https://bugs.ruby-lang.org/issues/10450

There is also an open issue proposing to change the current syntax error to a warning:

https://bugs.ruby-lang.org/issues/10617

According to Matz the issue seems to be that it's meaningless since multiple assignments always return an Array.

@enebo
Copy link
Member

enebo commented Jan 6, 2015

@tobiassvn yeah that is what I meant when I said it always evaluated true (re Matz comment). In any case, we will do whatever they determine in 10617. For older version compatibility we will just add the error check

@headius
Copy link
Member

headius commented Feb 1, 2023

We match CRuby's warning for this now, based on the end result of https://bugs.ruby-lang.org/issues/10617.

@headius headius closed this as completed Feb 1, 2023
@headius headius added this to the JRuby 9.4.0.0 milestone Feb 1, 2023
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