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

From: alxtskrnk@...
Date: 2014-12-18 07:41:38 UTC
List: ruby-core #66939
Issue #10450 has been updated by bug hit.


Martin D=C3=BCrst wrote:
> bug hit wrote:
> > Yusuke Endoh wrote:
> > > I think that the restriction is no longer meaningful, but it does not=
 mean that this is a bug.  Whatever the reason is, the behavior has been th=
e spec.  It is not harmful.  It is trivial to work around.  So I consider t=
his ticket as a feature request.
> > >=20
> > > I can reopen this ticket, but it has many noises and too long.  I als=
o recommend you to open a new ticket to feature request tracker.
>=20
> > If you can reopen, then please do, I think it's better not to have two =
tickets for the same issue.  I disagree that this is a feature.
>=20
> It would be helpful if you could defer the triage into bugs and features =
to people such as Yusuke who have a lot of experience with how Ruby develop=
ment works. Also, while it's better to not have two tickets for the same is=
sue, it's better to have a new ticket because, as we had to find out, the c=
urrent ticket mixes up two issues (allowing multiple assignment in conditio=
ns and removing parentheses), is confusing, and has accumulated a lot of du=
st.

Good point about the dust.  There are three entries in this bug that are es=
sential, my initial report, Alex Boyd's patch, and Yusuke Endoh's historica=
l explanation.  All of your posts are indeed dust that can and should be re=
moved, try to resist the urge to dust this bug any further.

There are not two issues here, just one, multiple assignment in conditional=
s is not possible. In the first post I provided examples to show that the p=
roblem is present with and without parens (with different errors), that's a=
 good thing, makes the bug report more thorough.

What horror, the confusion of absorbing two related facts instead of one, w=
hy, it's enough make your brain seize up.


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

* 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