[ruby-core:120618] [Ruby master Bug#21029] Prism behavior for `defined? (;x)` differs

Issue #21029 has been reported by qnighy (Masaki Hara). ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029 * Author: qnighy (Masaki Hara) * Status: Open * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by kddnewton (Kevin Newton). Assignee set to prism ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-111454 * Author: qnighy (Masaki Hara) * Status: Open * Assignee: prism * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by kddnewton (Kevin Newton). I think we should change `parse.y` to match this behavior. I will ask around. ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-111497 * Author: qnighy (Masaki Hara) * Status: Open * Assignee: prism * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by matz (Yukihiro Matsumoto). 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. ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-111865 * Author: qnighy (Masaki Hara) * Status: Assigned * Assignee: prism * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by qnighy (Masaki Hara).
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" ``` ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-111867 * Author: qnighy (Masaki Hara) * Status: Assigned * Assignee: prism * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by kddnewton (Kevin Newton). @matz 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 `;`? ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-111892 * Author: qnighy (Masaki Hara) * Status: Assigned * Assignee: prism * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by mame (Yusuke Endoh). 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 said "yes"; `defined? (x;)` should also return `"expression"`. ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-112296 * Author: qnighy (Masaki Hara) * Status: Assigned * Assignee: prism * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by kddnewton (Kevin Newton). 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. ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-112376 * Author: qnighy (Masaki Hara) * Status: Assigned * Assignee: prism * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by kddnewton (Kevin Newton). Assignee deleted (prism) ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-112377 * Author: qnighy (Masaki Hara) * Status: Assigned * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by S_H_ (Shun Hiraoka). I've fixed that defined? (x;) returns an expression when using parse.y. https://github.com/ruby/ruby/pull/13821 However, I have a little skeptical about whether this change is a good idea. If any other good suggestions, I would appreciate it if you could comment. ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-113959 * Author: qnighy (Masaki Hara) * Status: Closed * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by kddnewton (Kevin Newton). @S_H_ I agree, I think the overhead is not worth it in this case and we should pretend the `;` do not exist on both cases. ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-113960 * Author: qnighy (Masaki Hara) * Status: Closed * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/

Issue #21029 has been updated by S_H_ (Shun Hiraoka). I agree that consistent behavior between both cases would be ideal. Given the current structure of `parse.y`, wrapping with `NODE_BLOCK` seems like the most straightforward approach to make both `defined?(;x)` and `defined?(x;)` return `"expression"`. With my current changes, both forms now generate the same AST nodes, which I believe improves consistency across the board. Also, I want to clarify my earlier comment about being "skeptical" — I was specifically referring to adding new parameters to the `parser_params` struct, not to the `NODE_BLOCK` wrapping approach itself. Sorry for any confusion caused. Right now, the `defined?(x;)` test is failing on `parse.y`, which makes it hard to assess whether changes to `universal_parser.c` or other components are affecting the `parse.y` behavior. This adds friction when trying to work on parser-related modifications. From a maintenance standpoint, I believe fixing this failing test would help ensure that future `parse.y` changes can be validated more reliably. Would you be open to keeping this change in order to maintain test consistency? ---------------------------------------- Bug #21029: Prism behavior for `defined? (;x)` differs https://bugs.ruby-lang.org/issues/21029#change-114022 * Author: qnighy (Masaki Hara) * Status: Closed * ruby -v: ruby 3.5.0dev (2025-01-11T03:21:57Z master 1b3037081e) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Prism has a different behavior for `(;expr)` when used in `defined?` predicate: ```console % ./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. -- https://bugs.ruby-lang.org/
participants (5)
-
kddnewton (Kevin Newton)
-
mame (Yusuke Endoh)
-
matz (Yukihiro Matsumoto)
-
qnighy (Masaki Hara)
-
S_H_ (Shun Hiraoka)