Add more tests for type operators on the jvm

This commit is contained in:
Steven Schäfer
2019-05-22 14:42:05 +02:00
committed by max-kammerer
parent b6ea135e70
commit 6bf16a96e1
11 changed files with 99 additions and 5 deletions
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: test.kt
fun f(x: String) = "Fail 1"
fun box(): String {
return try {
f(J().s())
} catch (e: IllegalStateException) {
if (e.message == "J().s() must not be null")
"OK"
else
"Fail: ${e.message}"
}
}
// FILE: J.java
public class J {
public final String s() { return null; }
}
@@ -0,0 +1,20 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM_IR
// FILE: test.kt
fun f(x: String) = "Fail 1"
fun box(): String {
return try {
f(J.s())
} catch (e: IllegalStateException) {
if (e.message == "J.s() must not be null")
"OK"
else
"Fail: ${e.message}"
}
}
// FILE: J.java
public class J {
public static String s() { return null; }
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// FILE: Foo.java
public class Foo {
@@ -2,13 +2,13 @@
// 'as?' should be generated as a single 'safeAs...' intrinsic call
// without instanceof or 'is...'.
inline fun <reified T> safeAs(x: Any) {
x as? T
inline fun <reified T> safeAs(x: Any): T? {
return x as? T
}
fun test() {
val x: Any = arrayListOf("abc", "def")
safeAs<MutableList<*>>(x)
safeAs<MutableList<*>>(x)?.clear()
}
// 0 INSTANCEOF java/util/List
+1 -1
View File
@@ -8,7 +8,7 @@ inline fun <reified X> Any?.foo4() = foo2<X?>()
inline fun <reified A> Any?.foo5() = foo<A>()
// 1 LDC "T"
// 1 ICONST_1\s*LDC "T"\s*INVOKESTATIC kotlin/jvm/internal/Intrinsics.reifiedOperationMarker
// 1 LDC "Y\?"
// 1 LDC "Z\?"
// 1 LDC "X\?"
@@ -0,0 +1,15 @@
inline fun <reified T> Any?.foo() = this as? T
inline fun <reified Y> Any?.foo2() = foo<Y?>()
inline fun <reified Z> Any?.foo3() = foo2<Z>()
inline fun <reified X> Any?.foo4() = foo2<X?>()
inline fun <reified A> Any?.foo5() = foo<A>()
// 1 ICONST_2\s*LDC "T"\s*INVOKESTATIC kotlin/jvm/internal/Intrinsics.reifiedOperationMarker
// 1 LDC "Y\?"
// 1 LDC "Z\?"
// 1 LDC "X\?"
// 1 LDC "A"
@@ -14003,6 +14003,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt");
}
@TestMetadata("errorMessage.kt")
public void testErrorMessage() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt");
}
@TestMetadata("extensionReceiverParameter.kt")
public void testExtensionReceiverParameter() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/extensionReceiverParameter.kt");
@@ -14078,6 +14083,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt");
}
@TestMetadata("staticCallErrorMessage.kt")
public void testStaticCallErrorMessage() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt");
}
@TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -354,6 +354,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
runTest("compiler/testData/codegen/bytecodeText/reifiedIsCheckWithNullable.kt");
}
@TestMetadata("reifiedSafeAsCheck.kt")
public void testReifiedSafeAsCheck() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/reifiedSafeAsCheck.kt");
}
@TestMetadata("safeAsWithMutable.kt")
public void testSafeAsWithMutable() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/safeAsWithMutable.kt");
@@ -14003,6 +14003,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt");
}
@TestMetadata("errorMessage.kt")
public void testErrorMessage() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt");
}
@TestMetadata("extensionReceiverParameter.kt")
public void testExtensionReceiverParameter() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/extensionReceiverParameter.kt");
@@ -14078,6 +14083,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt");
}
@TestMetadata("staticCallErrorMessage.kt")
public void testStaticCallErrorMessage() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt");
}
@TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -12888,6 +12888,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/destructuringAssignmentWithNullabilityAssertionOnExtensionReceiver_lv12.kt");
}
@TestMetadata("errorMessage.kt")
public void testErrorMessage() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt");
}
@TestMetadata("extensionReceiverParameter.kt")
public void testExtensionReceiverParameter() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/extensionReceiverParameter.kt");
@@ -12963,6 +12968,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt");
}
@TestMetadata("staticCallErrorMessage.kt")
public void testStaticCallErrorMessage() throws Exception {
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt");
}
@TestMetadata("compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -354,6 +354,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
runTest("compiler/testData/codegen/bytecodeText/reifiedIsCheckWithNullable.kt");
}
@TestMetadata("reifiedSafeAsCheck.kt")
public void testReifiedSafeAsCheck() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/reifiedSafeAsCheck.kt");
}
@TestMetadata("safeAsWithMutable.kt")
public void testSafeAsWithMutable() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/safeAsWithMutable.kt");