EA-39177 - CCE: ArrayIterator.generate
If local variable is auto-casted to array, it should be iterated as array.
This commit is contained in:
@@ -680,8 +680,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
JetExpression loopRange = forExpression.getLoopRange();
|
||||
StackValue value = gen(loopRange);
|
||||
if (value instanceof StackValue.Local) {
|
||||
arrayVar = ((StackValue.Local) value).index;
|
||||
Type asmLoopRangeType = asmType(loopRangeType);
|
||||
if (value instanceof StackValue.Local && value.type.equals(asmLoopRangeType)) {
|
||||
arrayVar = ((StackValue.Local) value).index; // no need to copy local variable into another variable
|
||||
}
|
||||
else {
|
||||
arrayVar = myFrameMap.enterTemp(OBJECT_TYPE);
|
||||
@@ -691,7 +692,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
myFrameMap.leaveTemp(OBJECT_TYPE);
|
||||
}
|
||||
};
|
||||
Type asmLoopRangeType = asmType(loopRangeType);
|
||||
value.put(asmLoopRangeType, v);
|
||||
v.store(arrayVar, OBJECT_TYPE);
|
||||
}
|
||||
|
||||
@@ -819,6 +819,7 @@ public class CallResolver {
|
||||
ExpressionReceiver expressionReceiver = (ExpressionReceiver) original;
|
||||
if (autoCastReceiver.canCast()) {
|
||||
trace.record(AUTOCAST, expressionReceiver.getExpression(), autoCastReceiver.getType());
|
||||
trace.record(EXPRESSION_TYPE, expressionReceiver.getExpression(), autoCastReceiver.getType());
|
||||
}
|
||||
else {
|
||||
trace.report(AUTOCAST_IMPOSSIBLE.on(expressionReceiver.getExpression(), autoCastReceiver.getType(), expressionReceiver.getExpression().getText()));
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun f(x: Any?): String {
|
||||
if (x is Array<String>) {
|
||||
for (i in x) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return "FAIL"
|
||||
}
|
||||
|
||||
fun box(): String = f(Array<String>(1, {"OK"}))
|
||||
@@ -438,4 +438,10 @@ public class ControlStructuresTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxFile("controlStructures/longRange.jet");
|
||||
}
|
||||
|
||||
public void testForInSmartCastedToArray() {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxFile("controlStructures/forInSmartCastedToArray.kt");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user