Fix for KT-11762: "VerifyError: Bad local variable type" caused by explicit loop variable type

#KT-11762 Fixed
This commit is contained in:
Michael Bogdanov
2016-04-04 16:21:06 +03:00
parent f2237f675d
commit dec53c8d6c
4 changed files with 41 additions and 4 deletions
@@ -635,6 +635,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
protected final Type asmElementType;
protected int loopParameterVar;
protected Type loopParameterType;
private AbstractForLoopGenerator(@NotNull KtForExpression forExpression) {
this.forExpression = forExpression;
@@ -658,14 +659,14 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
if (loopParameter != null) {
// E e = tmp<iterator>.next()
final VariableDescriptor parameterDescriptor = bindingContext.get(VALUE_PARAMETER, loopParameter);
@SuppressWarnings("ConstantConditions") final Type asmTypeForParameter = asmType(parameterDescriptor.getType());
loopParameterVar = myFrameMap.enter(parameterDescriptor, asmTypeForParameter);
loopParameterType = asmType(parameterDescriptor.getType());
loopParameterVar = myFrameMap.enter(parameterDescriptor, loopParameterType);
scheduleLeaveVariable(new Runnable() {
@Override
public void run() {
myFrameMap.leave(parameterDescriptor);
v.visitLocalVariable(parameterDescriptor.getName().asString(),
asmTypeForParameter.getDescriptor(), null,
loopParameterType.getDescriptor(), null,
bodyStart, bodyEnd,
loopParameterVar);
}
@@ -676,6 +677,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
assert multiParameter != null;
// E tmp<e> = tmp<iterator>.next()
loopParameterType = asmElementType;
loopParameterVar = createLoopTempVariable(asmElementType);
}
}
@@ -843,7 +845,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
makeFakeCall(new TransientReceiver(iteratorCall.getResultingDescriptor().getReturnType()));
StackValue value = invokeFunction(fakeCall, nextCall, StackValue.local(iteratorVarIndex, asmTypeForIterator));
//noinspection ConstantConditions
StackValue.local(loopParameterVar, asmType(nextCall.getResultingDescriptor().getReturnType())).store(value, v);
StackValue.local(loopParameterVar, loopParameterType).store(value, v);
}
@Override
@@ -0,0 +1,11 @@
// WITH_RUNTIME
val alist = arrayListOf(1, 2, 3) // : j.u.ArrayList<k.Int>
fun box(): String {
var result = 0
for (i: Int in alist) {
result += i
}
return if (result == 6) "OK" else "fail: $result"
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
val alist = arrayListOf(1 to 2, 2 to 3, 3 to 4)
fun box(): String {
var result = 0
for ((i: Int, z: Int) in alist) {
result += i + z
}
return if (result == 15) "OK" else "fail: $result"
}
@@ -3517,6 +3517,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("forArrayList.kt")
public void testForArrayList() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forArrayList.kt");
doTest(fileName);
}
@TestMetadata("forArrayListMultiDecl.kt")
public void testForArrayListMultiDecl() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forArrayListMultiDecl.kt");
doTest(fileName);
}
@TestMetadata("forInSmartCastToArray.kt")
public void testForInSmartCastToArray() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSmartCastToArray.kt");