@@ -467,11 +467,23 @@ private Operand buildBegin(BeginNode node) {
467467
468468 private Operand buildBlock (BlockNode node ) {
469469 StaticScope staticScope = createStaticScopeFrom (node .locals , StaticScope .Type .BLOCK );
470+ markImplicitVariables (staticScope , node .locals , node .parameters );
470471 Signature signature = calculateSignature (node .parameters );
471472 staticScope .setSignature (signature );
472473 return buildIter (node .parameters , node .body , staticScope , signature , getLine (node ), getEndLine (node ));
473474 }
474475
476+ private void markImplicitVariables (StaticScope staticScope , RubySymbol [] locals , Node parameters ) {
477+ if (parameters instanceof NumberedParametersNode num ) markImplcitNums (staticScope , num .maximum );
478+ }
479+
480+ private void markImplcitNums (StaticScope staticScope , int maximum ) {
481+ for (int i = 0 ; i < maximum ; i ++) {
482+ int slot = staticScope .existsOrImplicit ("_" + (i + 1 ));
483+ staticScope .markImplicitVariable (slot & 0xffff );
484+ }
485+ }
486+
475487 protected Variable receiveBlockArg (Variable v , Operand argsArray , int argIndex , boolean isSplat ) {
476488 if (argsArray != null ) {
477489 // We are in a nested receive situation -- when we are not at the root of a masgn tree
@@ -1480,6 +1492,7 @@ private Operand buildKeywordHash(KeywordHashNode node, int[] flags) {
14801492
14811493 private Operand buildLambda (LambdaNode node ) {
14821494 StaticScope staticScope = createStaticScopeFrom (node .locals , StaticScope .Type .BLOCK );
1495+ markImplicitVariables (staticScope , node .locals , node .parameters );
14831496 Signature signature = calculateSignature (node .parameters );
14841497 staticScope .setSignature (signature );
14851498 return buildLambda (node .parameters , node .body , staticScope , signature , getLine (node ));
0 commit comments