diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt new file mode 100644 index 00000000000..a4d53008d54 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/errorMessage.kt @@ -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; } +} diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt new file mode 100644 index 00000000000..ab96a9c7f10 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/staticCallErrorMessage.kt @@ -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; } +} diff --git a/compiler/testData/codegen/boxAgainstJava/platformTypes/genericUnit.kt b/compiler/testData/codegen/boxAgainstJava/platformTypes/genericUnit.kt index e83bb32ba5a..092582f1f91 100644 --- a/compiler/testData/codegen/boxAgainstJava/platformTypes/genericUnit.kt +++ b/compiler/testData/codegen/boxAgainstJava/platformTypes/genericUnit.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FILE: Foo.java public class Foo { diff --git a/compiler/testData/codegen/bytecodeText/inline/reifiedSafeAsWithMutable.kt b/compiler/testData/codegen/bytecodeText/inline/reifiedSafeAsWithMutable.kt index 6e3c1429cb6..2416ca11cde 100644 --- a/compiler/testData/codegen/bytecodeText/inline/reifiedSafeAsWithMutable.kt +++ b/compiler/testData/codegen/bytecodeText/inline/reifiedSafeAsWithMutable.kt @@ -2,13 +2,13 @@ // 'as?' should be generated as a single 'safeAs...' intrinsic call // without instanceof or 'is...'. -inline fun safeAs(x: Any) { - x as? T +inline fun safeAs(x: Any): T? { + return x as? T } fun test() { val x: Any = arrayListOf("abc", "def") - safeAs>(x) + safeAs>(x)?.clear() } // 0 INSTANCEOF java/util/List diff --git a/compiler/testData/codegen/bytecodeText/reifiedAsCheck.kt b/compiler/testData/codegen/bytecodeText/reifiedAsCheck.kt index 52f46d22194..9fea579c726 100644 --- a/compiler/testData/codegen/bytecodeText/reifiedAsCheck.kt +++ b/compiler/testData/codegen/bytecodeText/reifiedAsCheck.kt @@ -8,7 +8,7 @@ inline fun Any?.foo4() = foo2() inline fun Any?.foo5() = foo() -// 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\?" diff --git a/compiler/testData/codegen/bytecodeText/reifiedSafeAsCheck.kt b/compiler/testData/codegen/bytecodeText/reifiedSafeAsCheck.kt new file mode 100644 index 00000000000..1cd5da8a137 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/reifiedSafeAsCheck.kt @@ -0,0 +1,15 @@ +inline fun Any?.foo() = this as? T + +inline fun Any?.foo2() = foo() + +inline fun Any?.foo3() = foo2() + +inline fun Any?.foo4() = foo2() + +inline fun Any?.foo5() = foo() + +// 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" diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index c23b7eb3b69..c05eee78096 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -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) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 2954c0fb083..0b3d15e8721 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index ec3ee5fca19..0435d77824f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 5cbc20e89fd..b302821adb5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -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) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index 85416cb030d..72f07099c2f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -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");