[ruby-core:66902] [ruby-trunk - Bug #10450] multiple assignment in conditional

From: alex@...
Date: 2014-12-17 09:33:15 UTC
List: ruby-core #66902
Issue #10450 has been updated by Alex Boyd.


Martin D=C3=BCrst wrote:
> It seems that both Matz and I got confused. That's not too surprising bec=
ause the first example has no parentheses.

An understandable mistake to make.

> I suggest the following:
>=20
> - Create a new issue that strictly concentrates on the case WITH parenthe=
ses.

Will do (or if bug hit gets around to it first, I'll follow his).

> - Beef up the pull request with the necessary changes to tests.

Aw, tests? You're going to make me write tests? :-)

Will do.
=20
> Please note that Matz can still reject the issue if he doesn't like it (e=
.g. because he feels it's too confusing,...).

Of course. I just want a potential rejection to be with all of the facts un=
derstood correctly, and it sounds like that's the case now.



----------------------------------------
Bug #10450: multiple assignment in conditional
https://bugs.ruby-lang.org/issues/10450#change-50451

* Author: bug hit
* Status: Rejected
* Priority: Normal
* Assignee:=20
* Category:=20
* Target version:=20
* ruby -v: ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
multiple assignment is an expression whose value can be truthy (array) or f=
alsy (nil, false), so why is there a restriction on its use in conditionals=
?  A warning perhaps is justified, but a syntax error, why?


irb(main):001:0> if a, b =3D nil then 1 else 0 end
SyntaxError: (irb):1: syntax error, unexpected ',', expecting keyword_then =
or ';' or '\n'
if a, b =3D nil then 1 else 0 end
     ^
(irb):1: syntax error, unexpected keyword_then, expecting end-of-input
if a, b =3D nil then 1 else 0 end
                  ^
	from /home/alex/.rbenv/versions/2.1.4/bin/irb:11:in `<main>'
irb(main):002:0> if (a, b =3D nil) then 1 else 0 end
SyntaxError: (irb):2: multiple assignment in conditional
	from /home/alex/.rbenv/versions/2.1.4/bin/irb:11:in `<main>'
irb(main):003:0> (a, b =3D nil) ? 1 : 0
SyntaxError: (irb):3: multiple assignment in conditional
	from /home/alex/.rbenv/versions/2.1.4/bin/irb:11:in `<main>'
irb(main):004:0> (a, b =3D nil)
=3D> nil




--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next