Project

General

Profile

Actions

Feature #18242

open

Parser makes multiple assignment sad in confusing way

Added by danh337 (Dan H) 3 months ago. Updated 3 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:105566]

Description

Example:

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) driver.rb Reproduce the errors danh337 (Dan H), 10/06/2021 04:37 AM
and-or-masgn-18242.diff (963 Bytes) and-or-masgn-18242.diff jeremyevans0 (Jeremy Evans), 10/06/2021 04:23 PM
driver.rb (2.1 KB) driver.rb Improved driver, more cases and error info danh337 (Dan H), 10/09/2021 02:39 AM
Actions

Also available in: Atom PDF