ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "danh337 (Dan H)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:105610] [Ruby master Feature#18242] Parser makes multiple assignment sad in confusing way
Date: Sat, 09 Oct 2021 02:40:09 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-94098.20211009024008.51329@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18242.20211006043959.51329@ruby-lang.org

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/

  parent reply	other threads:[~2021-10-09  2:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` danh337 (Dan H) [this message]
2021-10-09  7:58 ` [ruby-core:105615] " nobu (Nobuyoshi Nakada)

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-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-94098.20211009024008.51329@ruby-lang.org \
    --to=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 read-only IMAP folder(s) and NNTP newsgroup(s).