From: "jeremyevans0 (Jeremy Evans)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:105571] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
Date: Wed, 06 Oct 2021 16:28:10 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-94028.20211006162809.51329@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-18242.20211006043959.51329@ruby-lang.org>
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/
next prev parent reply other threads:[~2021-10-06 16:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-06 4:40 [ruby-core:105566] [Ruby master Bug#18242] " danh337 (Dan Higgins)
2021-10-06 16:28 ` jeremyevans0 (Jeremy Evans) [this message]
2021-10-06 20:56 ` [ruby-core:105581] [Ruby master Feature#18242] " 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.journal-94028.20211006162809.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).