* [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.
@ 2025-02-14 8:14 kinoppyd (Yasuhiro Kinoshita) via ruby-dev
2025-02-14 10:07 ` [ruby-dev:52151] " nobu (Nobuyoshi Nakada) via ruby-dev
2025-02-14 10:12 ` [ruby-dev:52152] " nobu (Nobuyoshi Nakada) via ruby-dev
0 siblings, 2 replies; 3+ messages in thread
From: kinoppyd (Yasuhiro Kinoshita) via ruby-dev @ 2025-02-14 8:14 UTC (permalink / raw)
To: ruby-dev; +Cc: kinoppyd (Yasuhiro Kinoshita)
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/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-dev:52151] [Ruby master Bug#21138] The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both.
2025-02-14 8:14 [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 kinoppyd (Yasuhiro Kinoshita) via ruby-dev
@ 2025-02-14 10:07 ` nobu (Nobuyoshi Nakada) via ruby-dev
2025-02-14 10:12 ` [ruby-dev:52152] " nobu (Nobuyoshi Nakada) via ruby-dev
1 sibling, 0 replies; 3+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-dev @ 2025-02-14 10:07 UTC (permalink / raw)
To: ruby-dev; +Cc: nobu (Nobuyoshi Nakada)
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/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-dev:52152] [Ruby master Bug#21138] The modifier expression with "it" is parsed differently in parse.y and Prism, which is unexpected in both.
2025-02-14 8:14 [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 kinoppyd (Yasuhiro Kinoshita) via ruby-dev
2025-02-14 10:07 ` [ruby-dev:52151] " nobu (Nobuyoshi Nakada) via ruby-dev
@ 2025-02-14 10:12 ` nobu (Nobuyoshi Nakada) via ruby-dev
1 sibling, 0 replies; 3+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-dev @ 2025-02-14 10:12 UTC (permalink / raw)
To: ruby-dev; +Cc: nobu (Nobuyoshi Nakada)
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/
_______________________________________________
ruby-dev mailing list -- ruby-dev@ml.ruby-lang.org
To unsubscribe send an email to ruby-dev-leave@ml.ruby-lang.org
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-14 10:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-14 8:14 [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 kinoppyd (Yasuhiro Kinoshita) via ruby-dev
2025-02-14 10:07 ` [ruby-dev:52151] " nobu (Nobuyoshi Nakada) via ruby-dev
2025-02-14 10:12 ` [ruby-dev:52152] " nobu (Nobuyoshi Nakada) via ruby-dev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).