Project

General

Profile

Actions

Bug #21029

closed

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

Added by qnighy (Masaki Hara) 3 months ago. Updated 11 days ago.

Status:
Closed
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) 3 months ago

  • Assignee set to prism

Updated by kddnewton (Kevin Newton) 2 months ago

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

Actions #3

Updated by hsbt (Hiroshi SHIBATA) about 2 months ago

  • Status changed from Open to Assigned

Updated by matz (Yukihiro Matsumoto) about 1 month 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) about 1 month 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) about 1 month 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 ;?

Updated by mame (Yusuke Endoh) 16 days ago

Discussed at the dev meeting.

kddnewton (Kevin Newton) wrote in #note-6:

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

@matz (Yukihiro Matsumoto) said "yes"; defined? (x;) should also return "expression".

Updated by kddnewton (Kevin Newton) 11 days ago

I have updated Prism with https://github.com/ruby/ruby/commit/adaaa7878ebee62888bf3547d14c1db4938da88a, but the added test fails for parse.y. I haven't had a chance to look at it yet, but maybe someone else with more familiarity could.

Updated by kddnewton (Kevin Newton) 11 days ago

  • Assignee deleted (prism)
Actions #10

Updated by kddnewton (Kevin Newton) 11 days ago

  • Status changed from Assigned to Closed

Applied in changeset git|adaaa7878ebee62888bf3547d14c1db4938da88a.


Handle void expressions in defined?

[Bug #21029]

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0