Fix for KT-15575: VerifyError: Bad type on operand stack

#KT-15575 Fixed
This commit is contained in:
Mikhael Bogdanov
2017-01-09 17:50:11 +01:00
parent a3f6fbe0c1
commit 2931c316a3
14 changed files with 123 additions and 4 deletions
@@ -161,7 +161,8 @@ public class AsmUtil {
return isPrimitiveClass((ClassDescriptor) descriptor) && !isBoolean((ClassDescriptor) descriptor);
}
public static Type correctElementType(Type type) {
@NotNull
public static Type correctElementType(@NotNull Type type) {
String internalName = type.getInternalName();
assert internalName.charAt(0) == '[';
return Type.getType(internalName.substring(1));
@@ -24,7 +24,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
class ArraySet : IntrinsicMethod() {
override fun toCallable(method: CallableMethod): Callable {
val type = correctElementType(method.dispatchReceiverType)
val type = correctElementType(method.dispatchReceiverType!!)
return object : IntrinsicCallable(
Type.VOID_TYPE,
listOf(Type.INT_TYPE, type),
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.codegen.optimization.common;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.codegen.AsmUtil;
import org.jetbrains.org.objectweb.asm.Handle;
import org.jetbrains.org.objectweb.asm.Opcodes;
import org.jetbrains.org.objectweb.asm.Type;
@@ -164,7 +165,7 @@ public class OptimizationBasicInterpreter extends Interpreter<BasicValue> implem
if (insn.getOpcode() == Opcodes.AALOAD) {
Type arrayType = value1.getType();
if (arrayType != null && arrayType.getSort() == Type.ARRAY) {
return new StrictBasicValue(arrayType.getElementType());
return new StrictBasicValue(AsmUtil.correctElementType(arrayType));
}
}
@@ -0,0 +1,9 @@
fun box(): String {
val array = arrayOf(doubleArrayOf(-1.0))
for (node in array) {
node[0] += 1.0
}
if (array[0][0] != 0.0) return "fail ${array[0][0]}"
return "OK"
}
@@ -0,0 +1,13 @@
fun box(): String {
val a = Array(2) { DoubleArray(3) }
for (i in 1..1) {
for (j in 0..2) {
a[i][j] += a[i - 1][j]
}
}
if (a[0][0] != 0.0) return "fail ${a[0][0]}"
return "OK"
}
@@ -0,0 +1,9 @@
fun box(): String {
val transform = transform(Array(1) { BooleanArray(1) })
if (!transform[0][0]) return "OK"
return "fail"
}
fun transform(screen: Array<BooleanArray>) = Array(1) { x ->
screen[x]
}
@@ -0,0 +1,4 @@
@kotlin.Metadata
public final class Kt15560Kt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}
@@ -0,0 +1,4 @@
@kotlin.Metadata
public final class Kt15568Kt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}
@@ -0,0 +1,5 @@
@kotlin.Metadata
public final class Kt15575Kt {
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
public final static @org.jetbrains.annotations.NotNull method transform(@org.jetbrains.annotations.NotNull p0: boolean[][]): boolean[][]
}
@@ -619,6 +619,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("kt15560.kt")
public void testKt15560() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt");
doTest(fileName);
}
@TestMetadata("kt15568.kt")
public void testKt15568() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt");
doTest(fileName);
}
@TestMetadata("kt15575.kt")
public void testKt15575() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt");
doTest(fileName);
}
@TestMetadata("MultiDeclFor.kt")
public void testMultiDeclFor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt");
@@ -619,6 +619,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("kt15560.kt")
public void testKt15560() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt");
doTest(fileName);
}
@TestMetadata("kt15568.kt")
public void testKt15568() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt");
doTest(fileName);
}
@TestMetadata("kt15575.kt")
public void testKt15575() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt");
doTest(fileName);
}
@TestMetadata("MultiDeclFor.kt")
public void testMultiDeclFor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt");
@@ -619,6 +619,24 @@ public class LightAnalysisModeCodegenTestGenerated extends AbstractLightAnalysis
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("kt15560.kt")
public void testKt15560() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt");
doTest(fileName);
}
@TestMetadata("kt15568.kt")
public void testKt15568() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt");
doTest(fileName);
}
@TestMetadata("kt15575.kt")
public void testKt15575() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt");
doTest(fileName);
}
@TestMetadata("MultiDeclFor.kt")
public void testMultiDeclFor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt");
@@ -859,6 +859,24 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
}
@TestMetadata("kt15560.kt")
public void testKt15560() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt");
doTest(fileName);
}
@TestMetadata("kt15568.kt")
public void testKt15568() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt");
doTest(fileName);
}
@TestMetadata("kt15575.kt")
public void testKt15575() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt");
doTest(fileName);
}
@TestMetadata("MultiDeclFor.kt")
public void testMultiDeclFor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt");
@@ -21,6 +21,7 @@ import com.sun.tools.javac.tree.JCTree
import com.sun.tools.javac.tree.TreeMaker
import com.sun.tools.javac.util.Context
import com.sun.tools.javac.util.Names
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.Type.*
@@ -30,7 +31,7 @@ class KaptTreeMaker(context: Context) : TreeMaker(context) {
fun Type(type: Type): JCTree.JCExpression {
convertBuiltinType(type)?.let { return it }
if (type.sort == ARRAY) {
return TypeArray(Type(type.elementType))
return TypeArray(Type(AsmUtil.correctElementType(type)))
}
return FqName(type.className)
}