From: "danh337 (Dan Higgins)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:105566] [Ruby master Bug#18242] Parser makes multiple assignment sad in confusing way
Date: Wed, 06 Oct 2021 04:40:00 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-18242.20211006043959.51329@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-18242.20211006043959.51329@ruby-lang.org>
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/
next parent reply other threads:[~2021-10-06 4:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-06 4:40 danh337 (Dan Higgins) [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-18242.20211006043959.51329@ruby-lang.org \
--to=noreply@ruby-lang.org \
--cc=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).