Project

General

Profile

Actions

Bug #21153

open

::Foo ||= p 1 should parse

Added by qnighy (Masaki Hara) about 15 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-02-22T15:11:40Z master fd882fb681) +PRISM [x86_64-linux]
[ruby-core:121141]

Description

There is an inconsistency between how Foo and ::Foo are handled:

% ./miniruby --parser=parse.y -e "Foo ||= p 1"
1
% ./miniruby --parser=parse.y -e "::Foo ||= p 1"
-e:1: syntax error, unexpected integer literal, expecting 'do' or '{' or '('
::Foo ||= p 1
./miniruby: compile error (SyntaxError)

Note that Object::Foo also parses.

Prism successfully parses both, which is what I expect.

% ./miniruby --parser=prism -e "Foo ||= p 1"
1
% ./miniruby --parser=prism -e "::Foo ||= p 1"
1

To fix this, you should probably handle all tOP_ASGNs in the op_asgn rule.

No data to display

Actions

Also available in: Atom PDF

Like0