Project

General

Profile

Actions

Bug #18629

closed

block args array splatting assigns to higher scope _ var

Added by Nakilon (Victor Maslov) 5 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:107883]

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) 5 months 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
Actions #2

Updated by nagachika (Tomoyuki Chikanaga) 4 months 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) 4 months 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

Actions #4

Updated by mame (Yusuke Endoh) 4 months ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF