Add a test for non-null assertions in local classes/functions
This commit is contained in:
@@ -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 <T, U> U passNull(Function<? super T, ? extends U> f) {
|
||||||
|
return f.apply(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
inline fun <T, U> 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"
|
||||||
|
}
|
||||||
+5
@@ -14221,6 +14221,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/incWithNullabilityAssertionOnExtensionReceiver_lv12.kt");
|
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")
|
@TestMetadata("mapPut.kt")
|
||||||
public void testMapPut() throws Exception {
|
public void testMapPut() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt");
|
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt");
|
||||||
|
|||||||
+5
@@ -14221,6 +14221,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/incWithNullabilityAssertionOnExtensionReceiver_lv12.kt");
|
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")
|
@TestMetadata("mapPut.kt")
|
||||||
public void testMapPut() throws Exception {
|
public void testMapPut() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt");
|
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt");
|
||||||
|
|||||||
+5
@@ -13106,6 +13106,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/incWithNullabilityAssertionOnExtensionReceiver_lv12.kt");
|
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")
|
@TestMetadata("mapPut.kt")
|
||||||
public void testMapPut() throws Exception {
|
public void testMapPut() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt");
|
runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/mapPut.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user