Bug #18629
closed
block args array splatting assigns to higher scope _ var
Added by Nakilon (Victor Maslov) over 2 years ago.
Updated over 1 year ago.
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)
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
- 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
- Status changed from Open to Closed
- 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.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0