ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "tenderlovemaking (Aaron Patterson) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "tenderlovemaking (Aaron Patterson)" <noreply@ruby-lang.org>
Subject: [ruby-core:122846] [Ruby Bug#21337] Using `not` on the RHS of a logical operator becomes valid syntax with Prism
Date: Wed, 23 Jul 2025 21:46:36 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-114135.20250723214636.9869@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-21337.20250514045744.9869@ruby-lang.org>

Issue #21337 has been updated by tenderlovemaking (Aaron Patterson).

Status changed from Assigned to Closed
Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED

I think this is fixed in 4cf85fe2140d0522f924ab57c850b2f03b967390

----------------------------------------
Bug #21337: Using `not` on the RHS of a logical operator becomes valid syntax with Prism
https://bugs.ruby-lang.org/issues/21337#change-114135

* Author: koic (Koichi ITO)
* Status: Closed
* Assignee: prism
* ruby -v: ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-darwin24]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED
----------------------------------------
The following syntax behavior differs between Ruby 3.3 (parse.y by default) and Ruby 3.4 (Prism by default).

```ruby
if true && not true; end
```

## Expected

In Ruby 3.3 and earlier, the following code results in a syntax error. The default parser is `parse.y`.

```console
$ ruby -vce 'if true && not true; end'
ruby 3.3.8 (2025-04-09 revision b200bad6cd) [x86_64-darwin24]
-e:1: syntax error, unexpected `true', expecting '('
if true && not true; end
ruby: compile error (SyntaxError)
```

The key point is that `not` is used on the right-hand side of a logical operator.

## Actual

When the default parser is switched to Prism, it is accepted as valid syntax with Ruby 3.4+ (Prism by default):

```console
$ ruby -vce 'if true && not true; end'
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-darwin24]
Syntax OK

$ ruby -vce 'if true && not true; end'
ruby 3.5.0dev (2025-05-13T02:05:19Z master 9b8c846bdf) +PRISM [x86_64-darwin24]
Syntax OK
```

Specifying parse.y causes a syntax error, as before 3.3 (parse.y by default):

```console
$ ruby -vce 'if true && not true; end'
ruby 3.3.8 (2025-04-09 revision b200bad6cd) [x86_64-darwin24]
-e:1: syntax error, unexpected `true', expecting '('
if true && not true; end
ruby: compile error (SyntaxError)

$ ruby --parser=parse.y -vce 'if true && not true; end'
ruby 3.5.0dev (2025-05-13T02:05:19Z master 9b8c846bdf) [x86_64-darwin24]
-e:1: syntax error, unexpected 'true', expecting '('
if true && not true; end
ruby: compile error (SyntaxError)
```

The behavior seen in the parse.y producing a syntax error might be probably the expected one.
Any case, it is likely that users would not expect such a discrepancy between parsers.

This issue was noticed in the context of the following RuboCop issue:
https://github.com/rubocop/rubocop/issues/14177



-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

  parent reply	other threads:[~2025-07-23 21:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14  4:57 [ruby-core:122086] " koic (Koichi ITO) via ruby-core
2025-05-14  7:03 ` [ruby-core:122089] " byroot (Jean Boussier) via ruby-core
2025-05-22  3:39 ` [ruby-core:122225] " Dan0042 (Daniel DeLorme) via ruby-core
2025-06-05  8:53 ` [ruby-core:122438] " matz (Yukihiro Matsumoto) via ruby-core
2025-06-05 10:52 ` [ruby-core:122450] " mame (Yusuke Endoh) via ruby-core
2025-07-23 21:46 ` tenderlovemaking (Aaron Patterson) via ruby-core [this message]
2025-09-15 22:27 ` [ruby-core:123255] " k0kubun (Takashi Kokubun) 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-114135.20250723214636.9869@ruby-lang.org \
    --to=ruby-core@ml.ruby-lang.org \
    --cc=noreply@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).