File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
src/main/java/org/truffleruby/parser Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -414,16 +414,20 @@ public RubyNode visitBeginNode(Nodes.BeginNode node) {
414
414
}
415
415
416
416
private RescueNode translateExceptionNodes (ArrayList <Nodes .Node > exceptionNodes , Nodes .RescueNode rescueClause ) {
417
- RubyNode translatedBody = translateNodeOrNil (rescueClause .statements );
418
417
419
418
final Nodes .Node [] exceptionNodesArray = exceptionNodes .toArray (Nodes .Node .EMPTY_ARRAY );
420
419
final RubyNode [] handlingClasses = translate (exceptionNodesArray );
421
420
421
+ RubyNode translatedBody ;
422
422
if (rescueClause .reference != null ) {
423
- final RubyNode exceptionWriteNode = translateRescueException (
424
- rescueClause .reference );
423
+ // We need to translate the reference before the statements,
424
+ // because the statements can use the variable defined by the reference.
425
+ final RubyNode exceptionWriteNode = translateRescueException (rescueClause .reference );
426
+ var translatedStatements = translateNodeOrNil (rescueClause .statements );
425
427
translatedBody = sequence (rescueClause ,
426
- Arrays .asList (exceptionWriteNode , translatedBody ));
428
+ Arrays .asList (exceptionWriteNode , translatedStatements ));
429
+ } else {
430
+ translatedBody = translateNodeOrNil (rescueClause .statements );
427
431
}
428
432
429
433
final RescueNode rescueNode = new RescueClassesNode (handlingClasses , translatedBody );
You can’t perform that action at this time.
0 commit comments