Issue #18242 has been updated by danh337 (Dan H).


jeremyevans0 (Jeremy Evans) wrote in #note-1:
> [...] Attached is a patch that implements the necessary parser rules, without causing any conflicts.  However, the patch doesn't include the parts needed to make ripper work, as I couldn't figure that out.  @nobu, any chance you could add the necessary code to make ripper work?

@jeremyevans0 you rock. Thanks sir.

----------------------------------------
Feature #18242: Parser makes multiple assignment sad in confusing way
https://bugs.ruby-lang.org/issues/18242#change-94050

* Author: danh337 (Dan H)
* Status: Open
* Priority: Normal
----------------------------------------
Example:
``` ruby
a, b = 2, 1     if 1 < 2     # Works
a, b = [2, 1]   if 1 < 2     # Works
(a, b) = 2, 1   if 1 < 2     # Works
(a, b) = [2, 1] if 1 < 2     # Works
(a, b = [2, 1]) if 1 < 2     # Works
a, b = 2, 1     unless 2 < 1 # Works
a, b = [2, 1]   unless 2 < 1 # Works
(a, b) = 2, 1   unless 2 < 1 # Works
(a, b) = [2, 1] unless 2 < 1 # Works
(a, b = [2, 1]) unless 2 < 1 # Works
1 < 2   and a, b = 2, 1      # SyntaxError
1 < 2   and a, b = [2, 1]    # SyntaxError
1 < 2   and (a, b) = 2, 1    # SyntaxError
1 < 2   and (a, b) = [2, 1]  # SyntaxError
(1 < 2) and a, b = 2, 1      # SyntaxError
(1 < 2) and a, b = [2, 1]    # SyntaxError
(1 < 2) and (a, b) = 2, 1    # SyntaxError
(1 < 2) and (a, b) = [2, 1]  # SyntaxError
1 < 2   and (a, b = 2, 1)    # Works
1 < 2   and (a, b = [2, 1])  # Works
2 < 1   or a, b = 2, 1       # SyntaxError
2 < 1   or a, b = [2, 1]     # SyntaxError
2 < 1   or (a, b) = 2, 1     # SyntaxError
2 < 1   or (a, b) = [2, 1]   # SyntaxError
(2 < 1) or a, b = 2, 1       # SyntaxError
(2 < 1) or a, b = [2, 1]     # SyntaxError
(2 < 1) or (a, b) = 2, 1     # SyntaxError
(2 < 1) or (a, b) = [2, 1]   # SyntaxError
2 < 1   or (a, b = 2, 1)     # Works
2 < 1   or (a, b = [2, 1])   # Works
```
Based on the precedence rules I've been able to find, all of these should work.

Believe it or not, there are cases where using `and` or `or` in a stanza of lines is much more readable.

Should the parser allow all of these? See attached driver script to reproduce this output.

---Files--------------------------------
driver.rb (1.17 KB)
and-or-masgn-18242.diff (963 Bytes)


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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>