ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way
@ 2021-10-06  4:40 danh337 (Dan Higgins)
  2021-10-06 16:28 ` [ruby-core:105571] [Ruby master Feature#18242] " jeremyevans0 (Jeremy Evans)
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: danh337 (Dan Higgins) @ 2021-10-06  4:40 UTC (permalink / raw)
  To: ruby-core

Issue #18242 has been reported by danh337 (Dan Higgins).

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

* Author: danh337 (Dan Higgins)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
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)


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:105571] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
  2021-10-06  4:40 [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way danh337 (Dan Higgins)
@ 2021-10-06 16:28 ` jeremyevans0 (Jeremy Evans)
  2021-10-06 20:56 ` [ruby-core:105581] " danh337 (Dan H)
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2021-10-06 16:28 UTC (permalink / raw)
  To: ruby-core

Issue #18242 has been updated by jeremyevans0 (Jeremy Evans).

Backport deleted (2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)
ruby -v deleted (ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux])
Tracker changed from Bug to Feature
File and-or-masgn-18242.diff added

The parser is currently not setup to handle this, so I don't think it is a bug.  You would have to add new parser rules to allow it, so I would consider this a feature request and not a bug.  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?

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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:105581] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
  2021-10-06  4:40 [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way danh337 (Dan Higgins)
  2021-10-06 16:28 ` [ruby-core:105571] [Ruby master Feature#18242] " jeremyevans0 (Jeremy Evans)
@ 2021-10-06 20:56 ` danh337 (Dan H)
  2021-10-07 15:44 ` [ruby-core:105592] " nobu (Nobuyoshi Nakada)
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: danh337 (Dan H) @ 2021-10-06 20:56 UTC (permalink / raw)
  To: ruby-core

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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:105592] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
  2021-10-06  4:40 [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way danh337 (Dan Higgins)
  2021-10-06 16:28 ` [ruby-core:105571] [Ruby master Feature#18242] " jeremyevans0 (Jeremy Evans)
  2021-10-06 20:56 ` [ruby-core:105581] " danh337 (Dan H)
@ 2021-10-07 15:44 ` nobu (Nobuyoshi Nakada)
  2021-10-08 19:40 ` [ruby-core:105608] " danh337 (Dan H)
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2021-10-07 15:44 UTC (permalink / raw)
  To: ruby-core

Issue #18242 has been updated by nobu (Nobuyoshi Nakada).


That patch seems not including `1 < 2 and a = 1, 2`.

https://github.com/ruby/ruby/pull/4945

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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:105608] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
  2021-10-06  4:40 [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way danh337 (Dan Higgins)
                   ` (2 preceding siblings ...)
  2021-10-07 15:44 ` [ruby-core:105592] " nobu (Nobuyoshi Nakada)
@ 2021-10-08 19:40 ` danh337 (Dan H)
  2021-10-09  2:36 ` [ruby-core:105609] " danh337 (Dan H)
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: danh337 (Dan H) @ 2021-10-08 19:40 UTC (permalink / raw)
  To: ruby-core

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


nobu (Nobuyoshi Nakada) wrote in #note-3:
> That patch seems not including `1 < 2 and a = 1, 2`.
> 
> https://github.com/ruby/ruby/pull/4945

Thank you @nobu !

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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:105609] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
  2021-10-06  4:40 [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way danh337 (Dan Higgins)
                   ` (3 preceding siblings ...)
  2021-10-08 19:40 ` [ruby-core:105608] " danh337 (Dan H)
@ 2021-10-09  2:36 ` danh337 (Dan H)
  2021-10-09  2:40 ` [ruby-core:105610] " danh337 (Dan H)
  2021-10-09  7:58 ` [ruby-core:105615] " nobu (Nobuyoshi Nakada)
  6 siblings, 0 replies; 8+ messages in thread
From: danh337 (Dan H) @ 2021-10-09  2:36 UTC (permalink / raw)
  To: ruby-core

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


@nobu I built your PR branch and confirmed that this new parsing works great with the `driver.rb` attached.

Will this patch have to wait for the 3.1.0 release? Sorry I'm not sure how the whole patching and backporting processes work. (But I'm pretty sure it can get complicated.) If these were syntax errors in the past, should the patch be safe for stable versions too?

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

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:105610] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
  2021-10-06  4:40 [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way danh337 (Dan Higgins)
                   ` (4 preceding siblings ...)
  2021-10-09  2:36 ` [ruby-core:105609] " danh337 (Dan H)
@ 2021-10-09  2:40 ` danh337 (Dan H)
  2021-10-09  7:58 ` [ruby-core:105615] " nobu (Nobuyoshi Nakada)
  6 siblings, 0 replies; 8+ messages in thread
From: danh337 (Dan H) @ 2021-10-09  2:40 UTC (permalink / raw)
  To: ruby-core

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

File driver.rb added

Attached is an improved driver. Again, every test case works with nobu's branch.

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

* 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)
driver.rb (2.1 KB)


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:105615] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
  2021-10-06  4:40 [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way danh337 (Dan Higgins)
                   ` (5 preceding siblings ...)
  2021-10-09  2:40 ` [ruby-core:105610] " danh337 (Dan H)
@ 2021-10-09  7:58 ` nobu (Nobuyoshi Nakada)
  6 siblings, 0 replies; 8+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2021-10-09  7:58 UTC (permalink / raw)
  To: ruby-core

Issue #18242 has been updated by nobu (Nobuyoshi Nakada).


I agree with @jeremyevans0 on that this is not a bug.
Feature requests need the approval by Matz to merge.

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

* 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)
driver.rb (2.1 KB)


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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-09  7:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06  4:40 [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way danh337 (Dan Higgins)
2021-10-06 16:28 ` [ruby-core:105571] [Ruby master Feature#18242] " jeremyevans0 (Jeremy Evans)
2021-10-06 20:56 ` [ruby-core:105581] " danh337 (Dan H)
2021-10-07 15:44 ` [ruby-core:105592] " nobu (Nobuyoshi Nakada)
2021-10-08 19:40 ` [ruby-core:105608] " danh337 (Dan H)
2021-10-09  2:36 ` [ruby-core:105609] " danh337 (Dan H)
2021-10-09  2:40 ` [ruby-core:105610] " danh337 (Dan H)
2021-10-09  7:58 ` [ruby-core:105615] " nobu (Nobuyoshi Nakada)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).