From: Joseph Jones Date: 2015-12-17T21:13:04-07:00 Subject: [ruby-core:72330] [Ruby trunk - Feature #10617] Change multiple assignment in conditional from parse error to warning --567387d0_5fb8011c_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 10, 2015 at 11:05= :50 MST, alxtskrnk=40gmail.com wrote:Issue =2310617 has been updated by b= ug hit.Why hasn't this been accepted=3F There is no good reason that an e= xpression that could be nil should not be testable.----------------------= ------------------=46eature =2310617: Change multiple assignment in condi= tional from parse error to warninghttps://bugs.ruby-lang.org/issues/10617= =23change-55449* Author: Recursive Madman* Status: Open* Priority: Normal= * Assignee: ----------------------------------------There is currently an= inconsistency between regular and multiple assignment in conditionals.Re= gular assignment causes a **warning**, multiple assignment causes a **par= se error**.The historical reason for this is that in 1.8 multiple assignm= ent would always return an Array, but since 1.9 it returns whatever the R= HS evaluates to.**Examples:**=60=60=60rubya, b =3D nil =23=3D> nila, b =3D= =5B=5D =23=3D> =5B=5D (but a and b are both nil)a, b =3D 1,2 =23=3D> =5B= 1, 2=5D=60=60=60Since multiple assignment behavior has changed, it makes = sense to remove the (artificial) parse error for multiple assignments.Tha= t makes it possible to test the return value of a method used for multipl= e assignment without having to use a temporary variable.**Example:**=60=60= =60ruby=23 CURRENTLY WORKING CODE:tmp =3D some=5Fmethod=5Freturning=5Farr= ay=5For=5Fnila, b =3D tmpif tmp =23 method returned an array (possibly em= pty)else =23 method returned nil.end=23 PROPOSED WORKING CODE:if(a, b =3D= some=5Fmethod=5Freturning=5Farray=5For=5Fnil) =23 method returned an arr= ay (possibly empty)else =23 method returned nilend=60=60=60(the parenthes= is are needed due to LALR limitations, as discussed in =2310450)Attached = is a patch that does the necessary change.---=46iles---------------------= -----------0001-turn-parse-error-on-multiple-assignment-into-warning.patc= h (752 Bytes)-- https://bugs.ruby-lang.org/ --567387d0_5fb8011c_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 10, 2015 at 11:05:50 MST, alxtskrnk=40gmail.com wrote:
Issue =2310617 has been upda= ted by bug hit.


Why hasn't this been accepted=3F There = is no good reason that an expression that could be nil should not be test= able.

----------------------------------------
=46eature = =2310617: Change multiple assignment in conditional from parse error to w= arning
https://bugs.ruby-lang.org/issues/10617=23change-55449
<= br />* Author: Recursive Madman
* Status: Open
* Priority: Norm= al
* Assignee:
----------------------------------------
T= here is currently an inconsistency between regular and multiple assignmen= t in conditionals.
Regular assignment causes a **warning**, multiple= assignment causes a **parse error**.

The historical reason fo= r this is that in 1.8 multiple assignment would always return an Array, b= ut since 1.9 it returns whatever the RHS evaluates to.

**Examp= les:**

=60=60=60ruby
a, b =3D nil =23=3D> nil
a, b = =3D =5B=5D =23=3D> =5B=5D (but a and b are both nil)
a, b =3D = 1,2 =23=3D> =5B1, 2=5D
=60=60=60

Since multiple assignme= nt behavior has changed, it makes sense to remove the (artificial) parse = error for multiple assignments.

That makes it possible to test= the return value of a method used for multiple assignment without having= to use a temporary variable.

**Example:**

=60=60=60= ruby
=23 CURRENTLY WORKING CODE:
tmp =3D some=5Fmethod=5Freturn= ing=5Farray=5For=5Fnil
a, b =3D tmp
if tmp
=23 method re= turned an array (possibly empty)
else
=23 method returned nil= .
end

=23 PROPOSED WORKING CODE:
if(a, b =3D some=5F= method=5Freturning=5Farray=5For=5Fnil)
=23 method returned an arra= y (possibly empty)
else
=23 method returned nil
end
=60=60=60

(the parenthesis are needed due to LALR limitations= , as discussed in =2310450)

Attached is a patch that does the = necessary change.


---=46iles----------------------------= ----
0001-turn-parse-error-on-multiple-assignment-into-warning.patch= (752 Bytes)


--
https://bugs.ruby-lang.org/
<= /blockquote>
--567387d0_5fb8011c_16c--