@@ -1328,7 +1328,8 @@ private RubySymbol defineMethod(RubyModule module, String name, RubyProc proc,
1328
1328
final RubyLambdaRootNode rootNode = RubyLambdaRootNode .of (callTargetForLambda );
1329
1329
final SharedMethodInfo info = proc .sharedMethodInfo .forDefineMethod (module , name );
1330
1330
final RubyNode body = rootNode .copyBody ();
1331
- final RubyNode newBody = new CallMethodWithLambdaBody (proc .declarationFrame , body );
1331
+ final RubyNode newBody = new CallMethodWithLambdaBody (isSingleContext () ? proc : null ,
1332
+ callTargetForLambda , body );
1332
1333
1333
1334
final RubyLambdaRootNode newRootNode = rootNode .copyRootNode (info , newBody );
1334
1335
final RootCallTarget newCallTarget = newRootNode .getCallTarget ();
@@ -1347,17 +1348,28 @@ private RubySymbol defineMethod(RubyModule module, String name, RubyProc proc,
1347
1348
1348
1349
private static class CallMethodWithLambdaBody extends RubyContextSourceNode {
1349
1350
1350
- private final MaterializedFrame declarationFrame ;
1351
+ private final RubyProc proc ;
1352
+ private final RootCallTarget lambdaCallTarget ;
1351
1353
@ Child private RubyNode lambdaBody ;
1352
1354
1353
- public CallMethodWithLambdaBody (MaterializedFrame declarationFrame , RubyNode lambdaBody ) {
1354
- this .declarationFrame = declarationFrame ;
1355
+ public CallMethodWithLambdaBody (RubyProc proc , RootCallTarget lambdaCallTarget , RubyNode lambdaBody ) {
1356
+ this .proc = proc ;
1357
+ this .lambdaCallTarget = lambdaCallTarget ;
1355
1358
this .lambdaBody = lambdaBody ;
1356
1359
}
1357
1360
1358
1361
@ Override
1359
1362
public Object execute (VirtualFrame frame ) {
1360
- RubyArguments .setDeclarationFrame (frame , declarationFrame );
1363
+ final RubyProc proc ;
1364
+ if (this .proc == null ) {
1365
+ proc = RubyArguments .getMethod (frame ).getProc ();
1366
+ assert proc .callTargets .getCallTargetForLambda () == lambdaCallTarget ;
1367
+ } else {
1368
+ assert RubyArguments .getMethod (frame ).getProc () == this .proc ;
1369
+ proc = this .proc ;
1370
+ }
1371
+
1372
+ RubyArguments .setDeclarationFrame (frame , proc .declarationFrame );
1361
1373
return lambdaBody .execute (frame );
1362
1374
}
1363
1375
0 commit comments