From b6a1154672ba43bc44bc6d942c1c686aca180706 Mon Sep 17 00:00:00 2001 From: pyos Date: Thu, 3 Oct 2019 09:55:45 +0200 Subject: [PATCH] Add a test for non-null assertions in local classes/functions --- .../notNullAssertions/localEntities.kt | 54 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 ++ .../LightAnalysisModeTestGenerated.java | 5 ++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 ++ 4 files changed, 69 insertions(+) create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/localEntities.kt diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/localEntities.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/localEntities.kt new file mode 100644 index 00000000000..0390f855876 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/localEntities.kt @@ -0,0 +1,54 @@ +// SKIP_JDK6 +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FULL_JDK +// FILE: F.java +import java.util.function.Function; + +public class F { + public static U passNull(Function f) { + return f.apply(null); + } +} + +// FILE: test.kt +inline fun expectAssertion(f: () -> (T) -> U): Unit? { + try { + F.passNull(f()) + } catch (e: IllegalArgumentException) { + return Unit + } + return null +} + +fun box(): String { + expectAssertion { + fun f(x: String) {} + ::f + } ?: return "FAIL: local function" + + expectAssertion { + class C(val x: String) + ::C + } ?: return "FAIL: local class constructor" + + expectAssertion { + class C(val x: String) { + fun foo(y: String) {} + } + C("")::foo + } ?: return "FAIL: local class method" + + expectAssertion { + val o = object { + fun foo(y: String) {} + } + o::foo + } ?: return "FAIL: anonymous object method" + + expectAssertion { + { it: String -> } + } ?: return "FAIL: lambda" + + return "OK" +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 1cb78747f98..d822e3bde2c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -14221,6 +14221,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/incWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } + @TestMetadata("localEntities.kt") + public void testLocalEntities() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/localEntities.kt"); + } + @TestMetadata("mapPut.kt") public void testMapPut() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 64770e2d0c9..54436ce5af1 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -14221,6 +14221,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/incWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } + @TestMetadata("localEntities.kt") + public void testLocalEntities() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/localEntities.kt"); + } + @TestMetadata("mapPut.kt") public void testMapPut() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 9b2e6745b14..32d93ae7790 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -13106,6 +13106,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/incWithNullabilityAssertionOnExtensionReceiver_lv12.kt"); } + @TestMetadata("localEntities.kt") + public void testLocalEntities() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/localEntities.kt"); + } + @TestMetadata("mapPut.kt") public void testMapPut() throws Exception { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt");