Don't remove nullability assertions of anonymous object transformation

#KT-19910 Fixed
This commit is contained in:
Mikhael Bogdanov
2017-09-01 15:02:36 +02:00
parent 599113b30f
commit 1cf8ee9433
4 changed files with 61 additions and 3 deletions
@@ -82,8 +82,12 @@ class MethodInliner(
//substitute returns with "goto end" instruction to keep non local returns in lambdas
val end = Label()
val isTransformingAnonymousObject = nodeRemapper is RegeneratedLambdaFieldRemapper
transformedNode = doInline(transformedNode)
removeClosureAssertions(transformedNode)
if (!isTransformingAnonymousObject) {
//don't remove assertion in transformed anonymous object
removeClosureAssertions(transformedNode)
}
transformedNode.instructions.resetLabels()
val resultNode = MethodNode(
@@ -93,7 +97,7 @@ class MethodInliner(
val visitor = RemapVisitor(
resultNode, remapper, nodeRemapper,
/*copy annotation and attributes*/
nodeRemapper is RegeneratedLambdaFieldRemapper
isTransformingAnonymousObject
)
try {
transformedNode.accept(visitor)
@@ -0,0 +1,39 @@
// FILE: J.java
// FULL_JDK
// WITH_RUNTIME
// TARGET_BACKEND: JVM
public class J {
public interface Consumer {
void accept(String p);
}
public static void invokeWithNull(Consumer x) {
x.accept(null);
}
}
// FILE: Kotlin.kt
inline fun makeRunnable(crossinline lambda: () -> Unit) =
object : Runnable {
override fun run() {
lambda()
}
}
fun box(): String {
try {
makeRunnable {
J.invokeWithNull(object : J.Consumer {
override fun accept(t: String) {
println(t)
}
})
}.run()
} catch (e: IllegalArgumentException) {
return "OK"
}
return "fail: exception expected"
}
@@ -124,7 +124,7 @@ object InlineTestUtil {
return null
}
override fun visitMethod(access: Int, name: String, desc: String, signature: String, exceptions: Array<String>): MethodVisitor? {
override fun visitMethod(access: Int, name: String, desc: String, signature: String?, exceptions: Array<String>?): MethodVisitor? {
if (skipMethodsOfThisClass) {
return null
}
@@ -354,6 +354,21 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxAga
}
}
@TestMetadata("compiler/testData/codegen/boxAgainstJava/inline")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Inline extends AbstractBlackBoxAgainstJavaCodegenTest {
public void testAllFilesPresentInInline() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxAgainstJava/inline"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("kt19910.kt")
public void testKt19910() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/inline/kt19910.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxAgainstJava/innerClass")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)