Partial fix for KT-16193: Incremental compilation generates invalid bytecode for crossinlined functions; avoid IllegalAccessError

This commit is contained in:
Mikhael Bogdanov
2017-03-01 10:05:25 +01:00
parent 3ad4f18e1a
commit 4d47c0fd63
4 changed files with 43 additions and 2 deletions
@@ -271,7 +271,7 @@ public class AnonymousObjectTransformer extends ObjectTransformer<AnonymousObjec
//TODO for inline method make public class
transformationInfo.setNewConstructorDescriptor(constructorDescriptor);
MethodVisitor constructorVisitor = classBuilder.newMethod(
NO_ORIGIN, AsmUtil.NO_FLAG_PACKAGE_PRIVATE, "<init>", constructorDescriptor, null, ArrayUtil.EMPTY_STRING_ARRAY
NO_ORIGIN, constructor.access, "<init>", constructorDescriptor, null, ArrayUtil.EMPTY_STRING_ARRAY
);
final Label newBodyStartLabel = new Label();
@@ -312,7 +312,7 @@ public class AnonymousObjectTransformer extends ObjectTransformer<AnonymousObjec
}
MethodNode intermediateMethodNode =
new MethodNode(AsmUtil.NO_FLAG_PACKAGE_PRIVATE, "<init>", constructorDescriptor, null, ArrayUtil.EMPTY_STRING_ARRAY);
new MethodNode(constructor.access, "<init>", constructorDescriptor, null, ArrayUtil.EMPTY_STRING_ARRAY);
inlineMethodAndUpdateGlobalResult(parentRemapper, intermediateMethodNode, constructor, constructorInlineBuilder, true);
InlineCodegenUtil.removeFinallyMarkers(intermediateMethodNode);
@@ -0,0 +1,29 @@
//WITH_RUNTIME
//FULL_JDK
// FILE: 1.kt
package test
inline fun crashMe(crossinline callback: () -> Unit): Function0<Unit> {
return object: Function0<Unit> {
override fun invoke() {
callback()
}
}
}
// FILE: 2.kt
import test.*
import java.lang.reflect.Modifier
var result = "fail"
fun box(): String {
val crashMe = crashMe { result = "OK" }
val modifiers = crashMe::class.java.getDeclaredConstructor().modifiers
if (!Modifier.isPublic(modifiers)) return "fail $modifiers"
crashMe.invoke()
return result
}
@@ -158,6 +158,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName);
}
@TestMetadata("kt16193.kt")
public void testKt16193() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt16193.kt");
doTest(fileName);
}
@TestMetadata("kt6552.kt")
public void testKt6552() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
@@ -158,6 +158,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName);
}
@TestMetadata("kt16193.kt")
public void testKt16193() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt16193.kt");
doTest(fileName);
}
@TestMetadata("kt6552.kt")
public void testKt6552() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");