@@ -837,11 +837,24 @@ public RubyNode visitCaseNode(CaseParseNode node) {
837
837
@ Override
838
838
public RubyNode visitCaseInNode (CaseInParseNode node ) {
839
839
final SourceIndexLength sourceSection = node .getPosition ();
840
- RubyNode caseExprValue = node .getCaseNode ().accept (this );
840
+
841
+ PatternMatchingTranslator translator = new PatternMatchingTranslator (language , source , parserContext ,
842
+ currentNode , node .getCases (), environment , this );
843
+
844
+ // Evaluate the case expression and store it in a local
845
+
846
+ final RubyNode caseExprValue = node .getCaseNode ().accept (this );
847
+ final int tempSlot = environment .declareLocalTemp ("case in value" );
848
+ final ReadLocalNode readTemp = environment .readNode (tempSlot , sourceSection );
849
+ final RubyNode assignTemp = readTemp .makeWriteNode (caseExprValue );
850
+
851
+ /* Build an if expression from the ins and else. Work backwards because the first if contains all the others in
852
+ * its else clause. */
853
+
841
854
RubyNode elseNode ;
842
855
if (node .getElseNode () == null ) {
843
856
RubyCallNodeParameters inspectCallParameters = new RubyCallNodeParameters (
844
- caseExprValue ,
857
+ NodeUtil . cloneNode ( readTemp ) ,
845
858
"inspect" ,
846
859
null ,
847
860
EmptyArgumentsDescriptor .INSTANCE ,
@@ -854,20 +867,6 @@ public RubyNode visitCaseInNode(CaseInParseNode node) {
854
867
elseNode = translateNodeOrNil (sourceSection , node .getElseNode ());
855
868
}
856
869
857
- PatternMatchingTranslator tr = new PatternMatchingTranslator (language , source , parserContext ,
858
- currentNode , node .getCaseNode (), node .getCases (), environment , this );
859
-
860
- final RubyNode ret ;
861
-
862
- // Evaluate the case expression and store it in a local
863
-
864
- final int tempSlot = environment .declareLocalTemp ("case in value" );
865
- final ReadLocalNode readTemp = environment .readNode (tempSlot , sourceSection );
866
- final RubyNode assignTemp = readTemp .makeWriteNode (caseExprValue );
867
-
868
- /* Build an if expression from the ins and else. Work backwards because the first if contains all the others in
869
- * its else clause. */
870
-
871
870
for (int n = node .getCases ().size () - 1 ; n >= 0 ; n --) {
872
871
final InParseNode in = (InParseNode ) node .getCases ().get (n );
873
872
@@ -876,7 +875,7 @@ public RubyNode visitCaseInNode(CaseInParseNode node) {
876
875
// us we-using the 'when' parser for 'in' temporarily.
877
876
final ParseNode patternNode = in .getExpressionNodes ();
878
877
879
- final RubyNode conditionNode = tr .translatePatternNode (patternNode , readTemp );
878
+ final RubyNode conditionNode = translator .translatePatternNode (patternNode , readTemp );
880
879
// Create the if node
881
880
final RubyNode thenNode = translateNodeOrNil (sourceSection , in .getBodyNode ());
882
881
final IfElseNode ifNode = new IfElseNode (conditionNode , thenNode , elseNode );
@@ -888,7 +887,7 @@ public RubyNode visitCaseInNode(CaseInParseNode node) {
888
887
final RubyNode ifNode = elseNode ;
889
888
890
889
// A top-level block assigns the temp then runs the if
891
- ret = sequence (sourceSection , Arrays .asList (assignTemp , ifNode ));
890
+ final RubyNode ret = sequence (sourceSection , Arrays .asList (assignTemp , ifNode ));
892
891
893
892
return addNewlineIfNeeded (node , ret );
894
893
}
0 commit comments