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)
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ 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] 9+ messages in thread

end of thread, other threads:[~2024-10-15 18:03 UTC | newest]

Thread overview: 9+ 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)
2024-10-15 18:02 ` [ruby-core:119530] " danh337 (Dan H) via ruby-core

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 NNTP newsgroup(s).