[ruby-core:122872] [Ruby Bug#21139] Prism and parse.y parses `it = it` differently
From:
"mame (Yusuke Endoh) via ruby-core" <ruby-core@...>
Date:
2025-07-28 15:51:14 UTC
List:
ruby-core #122872
Issue #21139 has been updated by mame (Yusuke Endoh).
@vinistock To clarify, do you want to change the scope of all variables, or only for `it`?
If you meant all variables, it would create a major incompatibility.
In an assignment `foo = expr`, the variable `foo` must be available in `expr`.
Changing this so that a variable is only defined lexically after `expr` would break this:
```ruby
fact = -> n do
# This call would be invalid because 'fact' is not available here
fact.call(n - 1)
end
```
Changing the scope of only a variable named `it` seems like an ad-hoc rule.
The syntax would be very hard to explain.
I think it would be far simpler to forbid `it` as a local variable name, though the compatibility implications would need to be carefully considered.
----------------------------------------
Bug #21139: Prism and parse.y parses `it = it` differently
https://bugs.ruby-lang.org/issues/21139#change-114175
* Author: tompng (tomoya ishida)
* Status: Feedback
* Assignee: prism
* ruby -v: ruby 3.5.0dev (2025-02-14T16:49:52Z master ee181d1bb7) +PRISM [x86_64-linux]
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
~~~
# ruby --parser=parse.y -e "42.tap { it = it; p it }"
nil
# ruby --parser=prism -e "42.tap { it = it; p it }"
42
~~~
---Files--------------------------------
clipboard-202503081702-idzz2.png (22.6 KB)
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/