Actions
Bug #18629
closedblock args array splatting assigns to higher scope _ var
Description
v = 1; [[2]].each{ |(v)| }; p v
_ = 1; [[2]].each{ |(_)| }; p _
prints
1
2
You can see here that v
is still 1
but _
isn't shadowed properly and is being assigned 2
.
Reproducible from 2.3.8 to 3.0.2 (macOS rbenv)
Updated by jeremyevans0 (Jeremy Evans) almost 3 years ago
I'm guessing this isn't a bug, because variables prefixed by _
(including _
itself) are supposed to be used in cases where you are ignoring the values. There are other cases where _
prefixed variables are special:
def a(b, b) end # SyntaxError
def a(_b, _b) end # no error
Updated by nagachika (Tomoyuki Chikanaga) over 2 years ago
- Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED
Updated by mame (Yusuke Endoh) over 2 years ago
This ticket was discussed at the dev meeting, and @matz (Yukihiro Matsumoto) said it should be fixed. @nobu (Nobuyoshi Nakada) has already committed a fix 3ddf6ad4d2f6dae4caa00b8c407768c7062099a0
Updated by mame (Yusuke Endoh) over 2 years ago
- Status changed from Open to Closed
Updated by nagachika (Tomoyuki Chikanaga) almost 2 years ago
- Backport changed from 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED to 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE
ruby_3_1 536f5ba0d48c033e63398d1751aebd0a11bcc6ff merged revision(s) 3ddf6ad4d2f6dae4caa00b8c407768c7062099a0.
Actions
Like0
Like0Like0Like0Like0Like0