@@ -1073,34 +1073,35 @@ protected int getLine(Node node) {
10731073 }
10741074
10751075 private void buildWhenSplatValues (Variable eqqResult , Node node , Operand testValue , Label bodyLabel ,
1076- Set <IRubyObject > seenLiterals ) {
1076+ Set <IRubyObject > seenLiterals , Map < IRubyObject , java . lang . Integer > origLocs ) {
10771077 if (node instanceof ListNode && !(node instanceof DNode ) && !(node instanceof ArrayNode )) {
1078- buildWhenValues (eqqResult , ((ListNode ) node ).children (), testValue , bodyLabel , seenLiterals );
1078+ buildWhenValues (eqqResult , ((ListNode ) node ).children (), testValue , bodyLabel , seenLiterals , origLocs );
10791079 } else if (node instanceof SplatNode ) {
1080- buildWhenValue (eqqResult , testValue , bodyLabel , node , seenLiterals , true );
1080+ buildWhenValue (eqqResult , testValue , bodyLabel , node , seenLiterals , origLocs , true );
10811081 } else if (node instanceof ArgsCatNode ) {
10821082 ArgsCatNode catNode = (ArgsCatNode ) node ;
1083- buildWhenSplatValues (eqqResult , catNode .getFirstNode (), testValue , bodyLabel , seenLiterals );
1084- buildWhenSplatValues (eqqResult , catNode .getSecondNode (), testValue , bodyLabel , seenLiterals );
1083+ buildWhenSplatValues (eqqResult , catNode .getFirstNode (), testValue , bodyLabel , seenLiterals , origLocs );
1084+ buildWhenSplatValues (eqqResult , catNode .getSecondNode (), testValue , bodyLabel , seenLiterals , origLocs );
10851085 } else if (node instanceof ArgsPushNode ) {
10861086 ArgsPushNode pushNode = (ArgsPushNode ) node ;
1087- buildWhenSplatValues (eqqResult , pushNode .getFirstNode (), testValue , bodyLabel , seenLiterals );
1088- buildWhenValue (eqqResult , testValue , bodyLabel , pushNode .getSecondNode (), seenLiterals , false );
1087+ buildWhenSplatValues (eqqResult , pushNode .getFirstNode (), testValue , bodyLabel , seenLiterals , origLocs );
1088+ buildWhenValue (eqqResult , testValue , bodyLabel , pushNode .getSecondNode (), seenLiterals , origLocs , false );
10891089 } else {
1090- buildWhenValue (eqqResult , testValue , bodyLabel , node , seenLiterals , true );
1090+ buildWhenValue (eqqResult , testValue , bodyLabel , node , seenLiterals , origLocs , true );
10911091 }
10921092 }
10931093
1094- protected void buildWhenArgs (WhenNode whenNode , Operand testValue , Label bodyLabel , Set <IRubyObject > seenLiterals ) {
1094+ protected void buildWhenArgs (WhenNode whenNode , Operand testValue , Label bodyLabel ,
1095+ Set <IRubyObject > seenLiterals , Map <IRubyObject , java .lang .Integer > origLocs ) {
10951096 Variable eqqResult = temp ();
10961097 Node exprNodes = whenNode .getExpressionNodes ();
10971098
10981099 if (exprNodes instanceof ListNode && !(exprNodes instanceof DNode ) && !(exprNodes instanceof ArrayNode ) && !(exprNodes instanceof ZArrayNode )) {
1099- buildWhenValues (eqqResult , ((ListNode ) exprNodes ).children (), testValue , bodyLabel , seenLiterals );
1100+ buildWhenValues (eqqResult , ((ListNode ) exprNodes ).children (), testValue , bodyLabel , seenLiterals , origLocs );
11001101 } else if (exprNodes instanceof ArgsPushNode || exprNodes instanceof SplatNode || exprNodes instanceof ArgsCatNode ) {
1101- buildWhenSplatValues (eqqResult , exprNodes , testValue , bodyLabel , seenLiterals );
1102+ buildWhenSplatValues (eqqResult , exprNodes , testValue , bodyLabel , seenLiterals , origLocs );
11021103 } else {
1103- buildWhenValue (eqqResult , testValue , bodyLabel , exprNodes , seenLiterals , false );
1104+ buildWhenValue (eqqResult , testValue , bodyLabel , exprNodes , seenLiterals , origLocs , false );
11041105 }
11051106 }
11061107
@@ -1164,6 +1165,7 @@ private <T extends Node & ILiteralNode> Variable buildOptimizedCaseWhen(
11641165 private <T extends Node & ILiteralNode > Map <java .lang .Integer , Label > gatherLiteralWhenBodies (
11651166 CaseNode caseNode , Map <Node , Label > nodeBodies , Function <T , Long > caseFunction ) {
11661167 Map <java .lang .Integer , Label > jumpTable = new HashMap <>();
1168+ Map <java .lang .Integer , Node > origTable = new HashMap <>();
11671169
11681170 // gather literal when bodies or bail
11691171 for (Node aCase : caseNode .getCases ().children ()) {
@@ -1176,9 +1178,11 @@ private <T extends Node & ILiteralNode> Map<java.lang.Integer, Label> gatherLite
11761178
11771179 if (jumpTable .get ((int ) exprLong ) == null ) {
11781180 jumpTable .put ((int ) exprLong , bodyLabel );
1181+ origTable .put ((int ) exprLong , whenNode );
11791182 nodeBodies .put (whenNode , bodyLabel );
11801183 } else {
1181- scope .getManager ().getRuntime ().getWarnings ().warning (IRubyWarnings .ID .MISCELLANEOUS , getFileName (), expr .getLine (), "duplicated when clause is ignored" );
1184+ getManager ().getRuntime ().getWarnings ().warning (IRubyWarnings .ID .MISCELLANEOUS , getFileName (), expr .getLine () + 1 ,
1185+ "duplicated 'when' clause with line " + (origTable .get ((int ) exprLong ).getLine () + 1 ) + " is ignored" );
11821186 }
11831187 }
11841188
0 commit comments