[ruby-dev:52150] [Ruby master Bug#21138] The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both.

Issue #21138 has been reported by kinoppyd (Yasuhiro Kinoshita). ---------------------------------------- Bug #21138: The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both. https://bugs.ruby-lang.org/issues/21138 * Author: kinoppyd (Yasuhiro Kinoshita) * Status: Open * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) [arm64-darwin21] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- ## Actual ### parse.y In parse.y, the block parameter "it" behaves as if it is not assigned. ```ruby # parse.y loop.rb:1:in 'block in <main>': undefined method '<' for nil (NoMethodError) 1.then { it *= 10 while it < 1000 } ^ from <internal:kernel>:126:in 'Kernel#then' from loop.rb:1:in '<main>' ``` ### prism In Prism, I may not understand what's happening due to my limited knowledge, but it results in a syntax error." ```ruby unexpected integer; expected an expression after the operator unexpected integer, expecting end-of-input
1 1.then { it *= 10 while it < 1000 }
loop.rb:1: syntax errors found (SyntaxError)
1 | 1.then { it *= 10 while it < 1000 } | ^~ unexpected integer; expected an expression after the operator | ^~ unexpected integer, expecting end-of-input
## Expected
'It' should be reassigned until it is greater than 1000.
--
https://bugs.ruby-lang.org/

Issue #21138 has been updated by nobu (Nobuyoshi Nakada). Assignee set to prism `it` is interpreted as an ordinary local variable, if there is the assignment, including operator-assign. The shortened example is: ```ruby 1.then { it = 1 } ``` The block should be called once and assign 1 to a local variable `it`. This works as expected with both of parse.y and prism. However, with the op-assign: ```ruby 1.then { it *= 1 } ``` parse.y parses the example as well as the previous example (but cannot run `it` is not assigned and is `nil`, and raises `NoMethodError` on `NilClass#*`). Prism seems to parse the simple assignment to `it` properly, but not op-assign. ---------------------------------------- Bug #21138: The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both. https://bugs.ruby-lang.org/issues/21138#change-111953 * Author: kinoppyd (Yasuhiro Kinoshita) * Status: Open * Assignee: prism * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) [arm64-darwin21] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- ## Actual ### parse.y In parse.y, the block parameter "it" behaves as if it is not assigned. ```ruby # parse.y loop.rb:1:in 'block in <main>': undefined method '<' for nil (NoMethodError) 1.then { it *= 10 while it < 1000 } ^ from <internal:kernel>:126:in 'Kernel#then' from loop.rb:1:in '<main>' ``` ### prism In Prism, I may not understand what's happening due to my limited knowledge, but it results in a syntax error." ```ruby unexpected integer; expected an expression after the operator unexpected integer, expecting end-of-input
1 1.then { it *= 10 while it < 1000 }
loop.rb:1: syntax errors found (SyntaxError)
1 | 1.then { it *= 10 while it < 1000 } | ^~ unexpected integer; expected an expression after the operator | ^~ unexpected integer, expecting end-of-input
## Expected
'It' should be reassigned until it is greater than 1000.
--
https://bugs.ruby-lang.org/

Issue #21138 has been updated by nobu (Nobuyoshi Nakada). nobu (Nobuyoshi Nakada) wrote in #note-1:
parse.y parses the example as well as the previous example (but cannot run `it` is not assigned and is `nil`, and raises `NoMethodError` on `NilClass#*`).
This error is what occurs from `it < 1000` in the your example. ---------------------------------------- Bug #21138: The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both. https://bugs.ruby-lang.org/issues/21138#change-111957 * Author: kinoppyd (Yasuhiro Kinoshita) * Status: Open * Assignee: prism * ruby -v: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) [arm64-darwin21] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- ## Actual ### parse.y In parse.y, the block parameter "it" behaves as if it is not assigned. ```ruby # parse.y loop.rb:1:in 'block in <main>': undefined method '<' for nil (NoMethodError) 1.then { it *= 10 while it < 1000 } ^ from <internal:kernel>:126:in 'Kernel#then' from loop.rb:1:in '<main>' ``` ### prism In Prism, I may not understand what's happening due to my limited knowledge, but it results in a syntax error." ```ruby unexpected integer; expected an expression after the operator unexpected integer, expecting end-of-input
1 1.then { it *= 10 while it < 1000 }
loop.rb:1: syntax errors found (SyntaxError)
1 | 1.then { it *= 10 while it < 1000 } | ^~ unexpected integer; expected an expression after the operator | ^~ unexpected integer, expecting end-of-input
## Expected
'It' should be reassigned until it is greater than 1000.
--
https://bugs.ruby-lang.org/
participants (2)
-
kinoppyd (Yasuhiro Kinoshita)
-
nobu (Nobuyoshi Nakada)