Bug #21138
closed
The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both.
Description
Actual¶
parse.y¶
In parse.y, the block parameter "it" behaves as if it is not assigned.
# 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."
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.
Updated by nobu (Nobuyoshi Nakada) 8 days ago
- Assignee set to prism
it
is interpreted as an ordinary local variable, if there is the assignment, including operator-assign.
The shortened example is:
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:
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.
Updated by nobu (Nobuyoshi Nakada) 8 days ago
- Is duplicate of Bug #21137: Compound assignment operator with "it" parsed differently between parse.y and prism added
Updated by nobu (Nobuyoshi Nakada) 8 days ago
ยท Edited
nobu (Nobuyoshi Nakada) wrote in #note-1:
parse.y parses the example as well as the previous example
(but cannot runit
is not assigned and isnil
, and raisesNoMethodError
onNilClass#*
).
This error is what occurs from it < 1000
in your example.
Updated by kddnewton (Kevin Newton) 8 days ago
- Status changed from Open to Closed
Applied in changeset git|ee181d1bb74ef82d6507c411a6aff10d1bf37aa3.
[ruby/prism] Fix up it indirect writes
Fixes [Bug #21137]
Updated by nobu (Nobuyoshi Nakada) 7 days ago
- Related to Bug #21139: Prism and parse.y parses `it = it` differently added