CARVIEW |
Select Language
HTTP/2 200
x-amz-id-2: dRKc3GSTQcnhyycSlM7rRhTnSJOMhkwqPKbo8AIxOV1FiXfyy0Z1whnRZiRrrvWNsEMzfsVoo0zkqfTtPIN+QVc4FDQ5U6tvQWAH9FGPVf0=
x-amz-request-id: ZRWZCXS8TH9VYZJJ
last-modified: Wed, 14 May 2025 05:02:00 GMT
etag: "eea416e305ba75fad0028b8f3ef5082c"
x-amz-server-side-encryption: AES256
server: AmazonS3
content-encoding: gzip
via: 1.1 varnish, 1.1 varnish
content-type: text/plain; charset=utf-8
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 20:23:35 GMT
x-served-by: cache-tyo11936-TYO, cache-bom-vanm7210046-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753302215.268426,VS0,VE318
vary: Accept-Encoding
content-length: 1012
From: "koic (Koichi ITO) via ruby-core"
Date: 2025-05-14T04:57:44+00:00
Subject: [ruby-core:122086] [Ruby Bug#21337] Using `not` on the RHS of a logical operator becomes valid syntax with Prism
Issue #21337 has been reported by koic (Koichi ITO).
----------------------------------------
Bug #21337: Using `not` on the RHS of a logical operator becomes valid syntax with Prism
https://bugs.ruby-lang.org/issues/21337
* Author: koic (Koichi ITO)
* Status: Open
* ruby -v: ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-darwin24]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
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/