Project

General

Profile

Actions

Bug #21029

open

Prism behavior for `defined? (;x)` differs

Added by qnighy (Masaki Hara) about 1 month ago. Updated 9 days ago.

Status:
Assigned
Assignee:
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux]
[ruby-core:120618]

Description

Prism has a different behavior for (;expr) when used in defined? predicate:

% ./miniruby --parser=prism -e "p defined? (;x)"
nil
% ./miniruby --parser=parse.y -e "p defined? (;x)"
"expression"

Although not a significant difference, aligning either of them with the other would be better.

Updated by kddnewton (Kevin Newton) about 1 month ago

  • Assignee set to prism

Updated by kddnewton (Kevin Newton) about 1 month ago

I think we should change parse.y to match this behavior. I will ask around.

Actions #3

Updated by hsbt (Hiroshi SHIBATA) 10 days ago

  • Status changed from Open to Assigned

Updated by matz (Yukihiro Matsumoto) 9 days ago

I think compound expressions (expressions (including empty) concatenated by semicolons) should be “expression” as parse.y.
It makes defined? simpler. I know the current defined? behavior recursively check for defined-ness (e.g., method parameters), I don't think we need that complexity here.

Matz.

Updated by qnighy (Masaki Hara) 9 days ago

I think compound expressions (expressions (including empty) concatenated by semicolons) should be “expression” as parse.y.

Interestingly enough though:

% ruby --parser=prism -e "p defined? (x;)"
nil
% ruby --parser=parse.y -e "p defined? (x;)"
nil

% ruby --parser=prism -e "p defined? (;x)"
nil
% ruby --parser=parse.y -e "p defined? (;x)"
"expression"

Updated by kddnewton (Kevin Newton) 9 days ago

@matz (Yukihiro Matsumoto) for what it's worth, it makes it much more complicated in the Prism compiler because we don't have empty statements. So it's not a recursive situation at the moment, it's just a single statement.

As @qnighy points out, should this be "expression" for when there is a trailing ;?

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0