From dd20b7403080ab208a4bf54189cca28ae61ced69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Tue, 2 Jul 2019 10:07:37 +0200 Subject: [PATCH] Split GenerateNotNullAssertionsTests into standard box and bytecode tests --- .../paramAssertionMessage.kt | 28 ++ .../notNullAssertions/callAssertions.kt | 126 +++++++++ .../doGenerateParamAssertions.kt | 36 +++ .../notNullAssertions/noCallAssertions.kt} | 68 ++++- .../notNullAssertions/arrayListGet.kt | 5 + .../assertionForNotNullCaptured.kt | 5 + .../assertionForNotNullTypeParam.kt | 3 + .../doNotGenerateParamAssertions.kt | 9 + .../javaMultipleSubstitutions.kt | 38 +++ .../noAssertionForNullableCaptured.kt | 5 + .../noAssertionForNullableGenericMethod.kt | 8 + ...noAssertionForNullableGenericMethodCall.kt | 11 + .../noAssertionForPrivateMethod.kt | 2 + .../noAssertionsForKotlin.kt | 33 +++ .../testData/codegen/notNullAssertions/A.java | 39 --- .../assertionForNotNullTypeParam.kt | 1 - .../doGenerateParamAssertions.java | 17 -- .../doGenerateParamAssertions.kt | 14 - .../doNotGenerateParamAssertions.kt | 4 - .../javaMultipleSubstitutions.java | 18 -- .../javaMultipleSubstitutions.kt | 5 - .../noAssertionForNullableGenericMethod.kt | 3 - ...noAssertionForNullableGenericMethodCall.kt | 7 - ...AbstractGenerateNotNullAssertionsTest.java | 103 ++++++++ ...ackBoxAgainstJavaCodegenTestGenerated.java | 15 ++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 + .../codegen/BytecodeTextTestGenerated.java | 63 +++++ .../GenerateNotNullAssertionsTest.java | 247 +----------------- .../LightAnalysisModeTestGenerated.java | 5 + ...ackBoxAgainstJavaCodegenTestGenerated.java | 15 ++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 + .../ir/IrBytecodeTextTestGenerated.java | 63 +++++ .../ir/IrGenerateNotNullAssertionsTest.java | 22 ++ 33 files changed, 668 insertions(+), 360 deletions(-) create mode 100644 compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt create mode 100644 compiler/testData/codegen/boxAgainstJava/notNullAssertions/callAssertions.kt create mode 100644 compiler/testData/codegen/boxAgainstJava/notNullAssertions/doGenerateParamAssertions.kt rename compiler/testData/codegen/{notNullAssertions/AssertionChecker.kt => boxAgainstJava/notNullAssertions/noCallAssertions.kt} (65%) rename compiler/testData/codegen/{ => bytecodeText}/notNullAssertions/arrayListGet.kt (51%) rename compiler/testData/codegen/{ => bytecodeText}/notNullAssertions/assertionForNotNullCaptured.kt (61%) create mode 100644 compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullTypeParam.kt create mode 100644 compiler/testData/codegen/bytecodeText/notNullAssertions/doNotGenerateParamAssertions.kt create mode 100644 compiler/testData/codegen/bytecodeText/notNullAssertions/javaMultipleSubstitutions.kt rename compiler/testData/codegen/{ => bytecodeText}/notNullAssertions/noAssertionForNullableCaptured.kt (50%) create mode 100644 compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethod.kt create mode 100644 compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethodCall.kt rename compiler/testData/codegen/{ => bytecodeText}/notNullAssertions/noAssertionForPrivateMethod.kt (57%) create mode 100644 compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionsForKotlin.kt delete mode 100644 compiler/testData/codegen/notNullAssertions/A.java delete mode 100644 compiler/testData/codegen/notNullAssertions/assertionForNotNullTypeParam.kt delete mode 100644 compiler/testData/codegen/notNullAssertions/doGenerateParamAssertions.java delete mode 100644 compiler/testData/codegen/notNullAssertions/doGenerateParamAssertions.kt delete mode 100644 compiler/testData/codegen/notNullAssertions/doNotGenerateParamAssertions.kt delete mode 100644 compiler/testData/codegen/notNullAssertions/javaMultipleSubstitutions.java delete mode 100644 compiler/testData/codegen/notNullAssertions/javaMultipleSubstitutions.kt delete mode 100644 compiler/testData/codegen/notNullAssertions/noAssertionForNullableGenericMethod.kt delete mode 100644 compiler/testData/codegen/notNullAssertions/noAssertionForNullableGenericMethodCall.kt create mode 100644 compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractGenerateNotNullAssertionsTest.java create mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/ir/IrGenerateNotNullAssertionsTest.java diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt new file mode 100644 index 00000000000..ac7fdbeb8d7 --- /dev/null +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.kt @@ -0,0 +1,28 @@ +// TARGET_BACKEND: JVM +// FILE: Test.java + +public class Test { + public static void callFoo() { + new A().foo(null); + } +} + +// FILE: Test.kt + +class A { + fun foo(s: String) {} +} + +fun box(): String { + try { + Test.callFoo() + return "Fail 1" + } catch (e : IllegalArgumentException) { + if (e.message != "Parameter specified as non-null is null: method A.foo, parameter s") { + return "Fail 2 (message: ${e.message})" + } + } catch (e : Throwable) { + return "Fail 3 (exception class: ${e::class.simpleName})" + } + return "OK" +} diff --git a/compiler/testData/codegen/boxAgainstJava/notNullAssertions/callAssertions.kt b/compiler/testData/codegen/boxAgainstJava/notNullAssertions/callAssertions.kt new file mode 100644 index 00000000000..4f3f68eb21a --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/notNullAssertions/callAssertions.kt @@ -0,0 +1,126 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS +// IGNORE_BACKEND: JVM_IR +// Missing IMPLICIT_NOTNULL casts +// FILE: A.java + +import org.jetbrains.annotations.NotNull; + +public class A { + @NotNull + public final String NULL = null; + + @NotNull + public static final String STATIC_NULL = null; + + public String foo() { + return null; + } + + public static String staticFoo() { + return null; + } + + public A plus(A a) { + return null; + } + + public A inc() { + return null; + } + + public Object get(Object o) { + return null; + } + + public A a() { return this; } + + public static class B { + public static B b() { return null; } + } + + public static class C { + public static C c() { return null; } + } +} + +// FILE: AssertionChecker.kt + +class AssertionChecker(val illegalStateExpected: Boolean) { + operator fun invoke(name: String, f: () -> Any) { + try { + f() + } catch (e: IllegalStateException) { + if (!illegalStateExpected) throw AssertionError("Unexpected IllegalStateException on calling $name") + return + } + if (illegalStateExpected) throw AssertionError("IllegalStateException expected on calling $name") + } +} + + +interface Tr { + fun foo(): String +} + +class Derived : A(), Tr { + override fun foo() = super.foo() +} + +class Delegated : Tr by Derived() { +} + +fun checkAssertions(illegalStateExpected: Boolean) { + val check = AssertionChecker(illegalStateExpected) + + // simple call + check("foo") { A().foo() } + + // simple static call + check("staticFoo") { A.staticFoo() } + + // supercall + check("foo") { Derived().foo() } + + // delegated call + check("foo") { Delegated().foo() } + + // collection element + check("get") { A()[""] } + + // binary expression + check("plus") { A() + A() } + + // field + check("NULL") { A().NULL } + + // static field + check("STATIC_NULL") { A.STATIC_NULL } + + // postfix expression + // TODO: +// check("inc") { var a = A().a(); a++ } + + // prefix expression + check("inc-b") { var a = A.B.b(); a++ } + + // prefix expression + check("inc-c") { var a = A.C.c(); a++ } + + // prefix expression + check("inc") { var a = A().a(); ++a } + + // prefix expression + check("inc-b") { var a = A.B.b(); ++a } + + // prefix expression + // TODO: +// check("inc-c") { var a = A.C.c(); ++a } +} + +operator fun A.C.inc(): A.C = A.C() +operator fun T.inc(): T = null as T + +fun box(): String { + checkAssertions(true) + return "OK" +} diff --git a/compiler/testData/codegen/boxAgainstJava/notNullAssertions/doGenerateParamAssertions.kt b/compiler/testData/codegen/boxAgainstJava/notNullAssertions/doGenerateParamAssertions.kt new file mode 100644 index 00000000000..5596a6c4077 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/notNullAssertions/doGenerateParamAssertions.kt @@ -0,0 +1,36 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_CALL_ASSERTIONS +// FILE: C.java +package test; + +import org.jetbrains.annotations.NotNull; + +public abstract class C { + + public abstract void doTest(@NotNull Type s); + + public static void runTest(C a) { + try { + a.doTest(null); + } catch (IllegalArgumentException e) { + return; + } + throw new AssertionError("Fail: IllegalArgumentException expected"); + } +} + +// FILE: B.kt +import test.C + +class TestString : C() { + override fun doTest(s: String) { } +} + +class TestUnit : C() { + override fun doTest(s: Unit) { } +} + +fun box(): String { + C.runTest(TestString()) + C.runTest(TestUnit()) + return "OK" +} diff --git a/compiler/testData/codegen/notNullAssertions/AssertionChecker.kt b/compiler/testData/codegen/boxAgainstJava/notNullAssertions/noCallAssertions.kt similarity index 65% rename from compiler/testData/codegen/notNullAssertions/AssertionChecker.kt rename to compiler/testData/codegen/boxAgainstJava/notNullAssertions/noCallAssertions.kt index 05c9d12b8f7..9e22074e572 100644 --- a/compiler/testData/codegen/notNullAssertions/AssertionChecker.kt +++ b/compiler/testData/codegen/boxAgainstJava/notNullAssertions/noCallAssertions.kt @@ -1,3 +1,49 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS, +JVM.DISABLE_CALL_ASSERTIONS +// IGNORE_BACKEND: JVM_IR +// FILE: A.java + +import org.jetbrains.annotations.NotNull; + +public class A { + @NotNull + public final String NULL = null; + + @NotNull + public static final String STATIC_NULL = null; + + public String foo() { + return null; + } + + public static String staticFoo() { + return null; + } + + public A plus(A a) { + return null; + } + + public A inc() { + return null; + } + + public Object get(Object o) { + return null; + } + + public A a() { return this; } + + public static class B { + public static B b() { return null; } + } + + public static class C { + public static C c() { return null; } + } +} + +// FILE: AssertionChecker.kt + class AssertionChecker(val illegalStateExpected: Boolean) { operator fun invoke(name: String, f: () -> Any) { try { @@ -22,31 +68,30 @@ class Derived : A(), Tr { class Delegated : Tr by Derived() { } - fun checkAssertions(illegalStateExpected: Boolean) { val check = AssertionChecker(illegalStateExpected) - + // simple call check("foo") { A().foo() } - + // simple static call check("staticFoo") { A.staticFoo() } - + // supercall check("foo") { Derived().foo() } - + // delegated call check("foo") { Delegated().foo() } - + // collection element check("get") { A()[""] } - + // binary expression check("plus") { A() + A() } - + // field check("NULL") { A().NULL } - + // static field check("STATIC_NULL") { A.STATIC_NULL } @@ -73,3 +118,8 @@ fun checkAssertions(illegalStateExpected: Boolean) { operator fun A.C.inc(): A.C = A.C() operator fun T.inc(): T = null as T + +fun box(): String { + checkAssertions(false) + return "OK" +} diff --git a/compiler/testData/codegen/notNullAssertions/arrayListGet.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt similarity index 51% rename from compiler/testData/codegen/notNullAssertions/arrayListGet.kt rename to compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt index bd32e460fc1..a053458abc3 100644 --- a/compiler/testData/codegen/notNullAssertions/arrayListGet.kt +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt @@ -1,3 +1,5 @@ +// IGNORE_BACKEND: JVM_IR +// Missing IMPLICIT_NOTNULL casts import java.util.ArrayList fun foo(): Any { @@ -7,3 +9,6 @@ fun foo(): Any { fun bar(a: ArrayList) { } + +// 1 checkExpressionValueIsNotNull +// 1 checkParameterIsNotNull \ No newline at end of file diff --git a/compiler/testData/codegen/notNullAssertions/assertionForNotNullCaptured.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt similarity index 61% rename from compiler/testData/codegen/notNullAssertions/assertionForNotNullCaptured.kt rename to compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt index bd2cda22762..ac8b3bb13a3 100644 --- a/compiler/testData/codegen/notNullAssertions/assertionForNotNullCaptured.kt +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt @@ -1,3 +1,6 @@ +// IGNORE_BACKEND: JVM_IR +// Missing IMPLICIT_NOTNULL casts + class A { fun add(element: T) {} } @@ -5,3 +8,5 @@ class A { public fun foo(x: MutableCollection, block: java.util.AbstractList) { x.add(block.get(0)) } + +// 1 checkExpressionValueIsNotNull diff --git a/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullTypeParam.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullTypeParam.kt new file mode 100644 index 00000000000..566d6850d19 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullTypeParam.kt @@ -0,0 +1,3 @@ +fun foo(t: T) = t + +// 1 checkParameterIsNotNull diff --git a/compiler/testData/codegen/bytecodeText/notNullAssertions/doNotGenerateParamAssertions.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/doNotGenerateParamAssertions.kt new file mode 100644 index 00000000000..5419e3edd87 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/doNotGenerateParamAssertions.kt @@ -0,0 +1,9 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS +// IGNORE_BACKEND: JVM_IR + +class A { + fun foo(s: String) { + } +} + +// 0 kotlin/jvm/internal/Intrinsics diff --git a/compiler/testData/codegen/bytecodeText/notNullAssertions/javaMultipleSubstitutions.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/javaMultipleSubstitutions.kt new file mode 100644 index 00000000000..a43487739e4 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/javaMultipleSubstitutions.kt @@ -0,0 +1,38 @@ +// IGNORE_BACKEND: JVM_IR +// Missing IMPLICIT_NOTNULL casts +// FILE: A.java +import org.jetbrains.annotations.NotNull; + +class A { + @NotNull + T foo() { return null; } +} + +// FILE: B.java +import org.jetbrains.annotations.NotNull; + +class B extends A { + @Override + @NotNull + T foo() { return null; } +} + +// FILE: C.java +import org.jetbrains.annotations.NotNull; + +class C extends B { + @Override + @NotNull + String foo() { return null; } +} + +// FILE: javaMultipleSubstitutions.kt +internal fun bar(a: A, b: B, c: C) { + val sa: String = a.foo() + val sb: String = b.foo() + val sc: String = c.foo() +} + +// @JavaMultipleSubstitutionsKt.class +// 3 checkExpressionValueIsNotNull +// 3 checkParameterIsNotNull diff --git a/compiler/testData/codegen/notNullAssertions/noAssertionForNullableCaptured.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableCaptured.kt similarity index 50% rename from compiler/testData/codegen/notNullAssertions/noAssertionForNullableCaptured.kt rename to compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableCaptured.kt index 5cede7badaa..8d7a0e63f7d 100644 --- a/compiler/testData/codegen/notNullAssertions/noAssertionForNullableCaptured.kt +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableCaptured.kt @@ -1,3 +1,6 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS +// IGNORE_BACKEND: JVM_IR + class A { fun add(element: T) {} } @@ -5,3 +8,5 @@ class A { public fun foo(x: MutableCollection, block: () -> R) { x.add(block()) } + +// 0 kotlin/jvm/internal/Intrinsics diff --git a/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethod.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethod.kt new file mode 100644 index 00000000000..d15647f5136 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethod.kt @@ -0,0 +1,8 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS +// IGNORE_BACKEND: JVM_IR + +fun foo(a: List) { + val t: T = a.get(0) +} + +// 0 kotlin/jvm/internal/Intrinsics diff --git a/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethodCall.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethodCall.kt new file mode 100644 index 00000000000..1d0571bdbe2 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethodCall.kt @@ -0,0 +1,11 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS + +import java.util.HashMap + +class A { + fun main() { + HashMap()[""] + } +} + +// 0 kotlin/jvm/internal/Intrinsics diff --git a/compiler/testData/codegen/notNullAssertions/noAssertionForPrivateMethod.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForPrivateMethod.kt similarity index 57% rename from compiler/testData/codegen/notNullAssertions/noAssertionForPrivateMethod.kt rename to compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForPrivateMethod.kt index 49267bc3789..3160f934ed6 100644 --- a/compiler/testData/codegen/notNullAssertions/noAssertionForPrivateMethod.kt +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForPrivateMethod.kt @@ -2,3 +2,5 @@ class A { private fun foo(s: String) { } } + +// 0 kotlin/jvm/internal/Intrinsics diff --git a/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionsForKotlin.kt b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionsForKotlin.kt new file mode 100644 index 00000000000..c333a5f4de3 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionsForKotlin.kt @@ -0,0 +1,33 @@ +// KOTLIN_CONFIGURATION_FLAGS: +JVM.DISABLE_PARAM_ASSERTIONS +// FILE: noAssertionsForKotlin.kt + +class A { + val x: Int = 42 + + fun foo(): String = "" + + companion object { + val y: Any? = 239 + + fun bar(): String = "" + } +} + +fun baz(): String = "" + +// FILE: noAssertionsForKotlinMain.kt + +fun bar() { + val x = A().x + val foo = A().foo() + val y = A.y + val bar = A.bar() + val baz = baz() +} + +// @A.class: +// 0 kotlin/jvm/internal/Intrinsics +// @NoAssertionsForKotlinKt.class: +// 0 kotlin/jvm/internal/Intrinsics +// @NoAssertionsForKotlinMainKt.class: +// 0 kotlin/jvm/internal/Intrinsics diff --git a/compiler/testData/codegen/notNullAssertions/A.java b/compiler/testData/codegen/notNullAssertions/A.java deleted file mode 100644 index fefb390887b..00000000000 --- a/compiler/testData/codegen/notNullAssertions/A.java +++ /dev/null @@ -1,39 +0,0 @@ -import org.jetbrains.annotations.NotNull; - -public class A { - @NotNull - public final String NULL = null; - - @NotNull - public static final String STATIC_NULL = null; - - public String foo() { - return null; - } - - public static String staticFoo() { - return null; - } - - public A plus(A a) { - return null; - } - - public A inc() { - return null; - } - - public Object get(Object o) { - return null; - } - - public A a() { return this; } - - public static class B { - public static B b() { return null; } - } - - public static class C { - public static C c() { return null; } - } -} diff --git a/compiler/testData/codegen/notNullAssertions/assertionForNotNullTypeParam.kt b/compiler/testData/codegen/notNullAssertions/assertionForNotNullTypeParam.kt deleted file mode 100644 index 801a613e91c..00000000000 --- a/compiler/testData/codegen/notNullAssertions/assertionForNotNullTypeParam.kt +++ /dev/null @@ -1 +0,0 @@ -fun foo(t: T) = t diff --git a/compiler/testData/codegen/notNullAssertions/doGenerateParamAssertions.java b/compiler/testData/codegen/notNullAssertions/doGenerateParamAssertions.java deleted file mode 100644 index 147b5f5f921..00000000000 --- a/compiler/testData/codegen/notNullAssertions/doGenerateParamAssertions.java +++ /dev/null @@ -1,17 +0,0 @@ -package test; - -import org.jetbrains.annotations.NotNull; - -public abstract class doGenerateParamAssertions { - - public abstract void doTest(@NotNull Type s); - - public static void runTest(doGenerateParamAssertions a) { - try { - a.doTest(null); - } catch (IllegalArgumentException e) { - return; - } - throw new AssertionError("Fail: IllegalArgumentException expected"); - } -} diff --git a/compiler/testData/codegen/notNullAssertions/doGenerateParamAssertions.kt b/compiler/testData/codegen/notNullAssertions/doGenerateParamAssertions.kt deleted file mode 100644 index 48ec8525c4b..00000000000 --- a/compiler/testData/codegen/notNullAssertions/doGenerateParamAssertions.kt +++ /dev/null @@ -1,14 +0,0 @@ -import test.doGenerateParamAssertions as C - -class TestString : C() { - override fun doTest(s: String) { } -} - -class TestUnit : C() { - override fun doTest(s: Unit) { } -} - -fun doTest() { - C.runTest(TestString()) - C.runTest(TestUnit()) -} diff --git a/compiler/testData/codegen/notNullAssertions/doNotGenerateParamAssertions.kt b/compiler/testData/codegen/notNullAssertions/doNotGenerateParamAssertions.kt deleted file mode 100644 index a702af9e5bb..00000000000 --- a/compiler/testData/codegen/notNullAssertions/doNotGenerateParamAssertions.kt +++ /dev/null @@ -1,4 +0,0 @@ -class A { - fun foo(s: String) { - } -} diff --git a/compiler/testData/codegen/notNullAssertions/javaMultipleSubstitutions.java b/compiler/testData/codegen/notNullAssertions/javaMultipleSubstitutions.java deleted file mode 100644 index 07e6b9c7168..00000000000 --- a/compiler/testData/codegen/notNullAssertions/javaMultipleSubstitutions.java +++ /dev/null @@ -1,18 +0,0 @@ -import org.jetbrains.annotations.NotNull; - -class A { - @NotNull - T foo() { return null; } -} - -class B extends A { - @Override - @NotNull - T foo() { return null; } -} - -class C extends B { - @Override - @NotNull - String foo() { return null; } -} diff --git a/compiler/testData/codegen/notNullAssertions/javaMultipleSubstitutions.kt b/compiler/testData/codegen/notNullAssertions/javaMultipleSubstitutions.kt deleted file mode 100644 index a6bfa7acdaa..00000000000 --- a/compiler/testData/codegen/notNullAssertions/javaMultipleSubstitutions.kt +++ /dev/null @@ -1,5 +0,0 @@ -internal fun bar(a: A, b: B, c: C) { - val sa: String = a.foo() - val sb: String = b.foo() - val sc: String = c.foo() -} diff --git a/compiler/testData/codegen/notNullAssertions/noAssertionForNullableGenericMethod.kt b/compiler/testData/codegen/notNullAssertions/noAssertionForNullableGenericMethod.kt deleted file mode 100644 index 0298eb1c1cb..00000000000 --- a/compiler/testData/codegen/notNullAssertions/noAssertionForNullableGenericMethod.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun foo(a: List) { - val t: T = a.get(0) -} diff --git a/compiler/testData/codegen/notNullAssertions/noAssertionForNullableGenericMethodCall.kt b/compiler/testData/codegen/notNullAssertions/noAssertionForNullableGenericMethodCall.kt deleted file mode 100644 index 112dbdbaf34..00000000000 --- a/compiler/testData/codegen/notNullAssertions/noAssertionForNullableGenericMethodCall.kt +++ /dev/null @@ -1,7 +0,0 @@ -import java.util.HashMap - -class A { - fun main() { - HashMap()[""] - } -} \ No newline at end of file diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractGenerateNotNullAssertionsTest.java b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractGenerateNotNullAssertionsTest.java new file mode 100644 index 00000000000..7e7bd06eb8d --- /dev/null +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractGenerateNotNullAssertionsTest.java @@ -0,0 +1,103 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen; + +import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.backend.common.output.OutputFile; +import org.jetbrains.kotlin.backend.common.output.OutputFileCollection; +import org.jetbrains.kotlin.cli.common.output.OutputUtilsKt; +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; +import org.jetbrains.kotlin.config.CompilerConfiguration; +import org.jetbrains.kotlin.config.JVMConfigurationKeys; +import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil; +import org.jetbrains.kotlin.psi.KtFile; +import org.jetbrains.kotlin.test.ConfigurationKind; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TestJdkKind; +import org.jetbrains.org.objectweb.asm.ClassReader; +import org.jetbrains.org.objectweb.asm.ClassVisitor; +import org.jetbrains.org.objectweb.asm.MethodVisitor; +import org.jetbrains.org.objectweb.asm.Opcodes; + +import java.io.File; + +// TODO Remove this class once general multi-module bytecode text tests are implemented. +abstract public class AbstractGenerateNotNullAssertionsTest extends CodegenTestCase { + @NotNull + @Override + protected String getPrefix() { + return "notNullAssertions"; + } + + private void setUpEnvironment(boolean disableCallAssertions, boolean disableParamAssertions) { + File[] extraClassPath = javaClassesOutputDirectory != null ? new File[] {javaClassesOutputDirectory} : new File[0]; + CompilerConfiguration configuration = + KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, extraClassPath); + + configuration.put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, disableCallAssertions); + configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, disableParamAssertions); + updateConfiguration(configuration); + + myEnvironment = + KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES); + myFiles = null; + } + + private void loadSource(@NotNull String fileName) { + loadFileByFullPath(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName); + } + + protected void doTestNoAssertionsForKotlinFromBinary(String binaryDependencyFilename, String testFilename) { + setUpEnvironment(false, true); + loadSource(binaryDependencyFilename); + OutputFileCollection outputFiles = generateClassesInFile(); + javaClassesOutputDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes"); + OutputUtilsKt.writeAllTo(outputFiles, javaClassesOutputDirectory); + + setUpEnvironment(false, true); + loadSource(testFilename); + + assertNoIntrinsicsMethodIsCalledInMyClasses(false); + } + + private void assertNoIntrinsicsMethodIsCalledInMyClasses(boolean noClassFileIsAnError) { + for (KtFile jetFile : myFiles.getPsiFiles()) { + String fileClassName = JvmFileClassUtil.getFileClassInfoNoResolve(jetFile).getFileClassFqName().asString(); + assertNoIntrinsicsMethodIsCalled(fileClassName, noClassFileIsAnError); + } + } + + private void assertNoIntrinsicsMethodIsCalled(String className, boolean noClassFileIsAnError) { + OutputFileCollection classes = generateClassesInFile(); + OutputFile file = classes.get(className + ".class"); + if (noClassFileIsAnError) { + assertNotNull("File for " + className + " is absent", file); + } + else if (file == null) { + return; + } + ClassReader reader = new ClassReader(file.asByteArray()); + + reader.accept(new ClassVisitor(Opcodes.API_VERSION) { + @Override + public MethodVisitor visitMethod( + int access, @NotNull String callerName, @NotNull String callerDesc, String signature, String[] exceptions + ) { + return new MethodVisitor(Opcodes.API_VERSION) { + @Override + public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { + assertFalse( + "Intrinsics method is called: " + name + desc + " Caller: " + callerName + callerDesc, + "kotlin/jvm/internal/Intrinsics".equals(owner) + ); + } + }; + } + }, 0); + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java index 6954931e79b..6c6ba43405a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java @@ -442,11 +442,26 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxAga KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxAgainstJava/notNullAssertions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("callAssertions.kt") + public void testCallAssertions() throws Exception { + runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/callAssertions.kt"); + } + @TestMetadata("delegation.kt") public void testDelegation() throws Exception { runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/delegation.kt"); } + @TestMetadata("doGenerateParamAssertions.kt") + public void testDoGenerateParamAssertions() throws Exception { + runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/doGenerateParamAssertions.kt"); + } + + @TestMetadata("noCallAssertions.kt") + public void testNoCallAssertions() throws Exception { + runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/noCallAssertions.kt"); + } + @TestMetadata("rightElvisOperand.kt") public void testRightElvisOperand() throws Exception { runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/rightElvisOperand.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 9d95b026467..95d37cd0628 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -13988,6 +13988,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver_lv12.kt"); } + @TestMetadata("paramAssertionMessage.kt") + public void testParamAssertionMessage() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.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 1eb67448762..78b2e491e08 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -3073,6 +3073,69 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { } } + @TestMetadata("compiler/testData/codegen/bytecodeText/notNullAssertions") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class NotNullAssertions extends AbstractBytecodeTextTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInNotNullAssertions() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/notNullAssertions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("arrayListGet.kt") + public void testArrayListGet() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt"); + } + + @TestMetadata("assertionForNotNullCaptured.kt") + public void testAssertionForNotNullCaptured() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt"); + } + + @TestMetadata("assertionForNotNullTypeParam.kt") + public void testAssertionForNotNullTypeParam() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullTypeParam.kt"); + } + + @TestMetadata("doNotGenerateParamAssertions.kt") + public void testDoNotGenerateParamAssertions() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/doNotGenerateParamAssertions.kt"); + } + + @TestMetadata("javaMultipleSubstitutions.kt") + public void testJavaMultipleSubstitutions() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/javaMultipleSubstitutions.kt"); + } + + @TestMetadata("noAssertionForNullableCaptured.kt") + public void testNoAssertionForNullableCaptured() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableCaptured.kt"); + } + + @TestMetadata("noAssertionForNullableGenericMethod.kt") + public void testNoAssertionForNullableGenericMethod() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethod.kt"); + } + + @TestMetadata("noAssertionForNullableGenericMethodCall.kt") + public void testNoAssertionForNullableGenericMethodCall() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethodCall.kt"); + } + + @TestMetadata("noAssertionForPrivateMethod.kt") + public void testNoAssertionForPrivateMethod() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForPrivateMethod.kt"); + } + + @TestMetadata("noAssertionsForKotlin.kt") + public void testNoAssertionsForKotlin() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionsForKotlin.kt"); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeText/nullCheckOptimization") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/GenerateNotNullAssertionsTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/GenerateNotNullAssertionsTest.java index edf2abc89a0..d05131d0137 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/GenerateNotNullAssertionsTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/GenerateNotNullAssertionsTest.java @@ -1,251 +1,12 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.codegen; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.text.StringUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.backend.common.output.OutputFile; -import org.jetbrains.kotlin.backend.common.output.OutputFileCollection; -import org.jetbrains.kotlin.cli.common.output.OutputUtilsKt; -import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; -import org.jetbrains.kotlin.config.CompilerConfiguration; -import org.jetbrains.kotlin.config.JVMConfigurationKeys; -import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil; -import org.jetbrains.kotlin.psi.KtFile; -import org.jetbrains.kotlin.test.ConfigurationKind; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.TestJdkKind; -import org.jetbrains.org.objectweb.asm.ClassReader; -import org.jetbrains.org.objectweb.asm.ClassVisitor; -import org.jetbrains.org.objectweb.asm.MethodVisitor; -import org.jetbrains.org.objectweb.asm.Opcodes; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.util.Collections; - -public class GenerateNotNullAssertionsTest extends CodegenTestCase { - @NotNull - @Override - protected String getPrefix() { - return "notNullAssertions"; - } - - private void setUpEnvironment(boolean disableCallAssertions, boolean disableParamAssertions) { - File[] extraClassPath = javaClassesOutputDirectory != null ? new File[] {javaClassesOutputDirectory} : new File[0]; - CompilerConfiguration configuration = - KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, extraClassPath); - - configuration.put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, disableCallAssertions); - configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, disableParamAssertions); - - myEnvironment = - KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES); - myFiles = null; - } - - private void loadSource(@NotNull String fileName) { - loadFileByFullPath(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName); - } - - private void compileJava(@NotNull String fileName) { - javaClassesOutputDirectory = CodegenTestUtil.compileJava( - Collections.singletonList(KotlinTestUtils.getTestDataPathBase() + "/codegen/" + getPrefix() + "/" + fileName), - Collections.emptyList(), - Collections.emptyList() - ); - } - - private void doTestCallAssertions(boolean disableCallAssertions) throws Exception { - compileJava("A.java"); - setUpEnvironment(disableCallAssertions, true); - - loadSource("AssertionChecker.kt"); - generateFunction("checkAssertions").invoke(null, !disableCallAssertions); - } - - public void testGenerateAssertions() throws Exception { - doTestCallAssertions(false); - } - - public void testDoNotGenerateAssertions() throws Exception { - doTestCallAssertions(true); - } - - public void testNoAssertionsForKotlinFromSource() { - setUpEnvironment(false, true); - - loadFiles(getPrefix() + "/noAssertionsForKotlin.kt", getPrefix() + "/noAssertionsForKotlinMain.kt"); - - assertNoIntrinsicsMethodIsCalledInMyClasses(true); - } - +public class GenerateNotNullAssertionsTest extends AbstractGenerateNotNullAssertionsTest { public void testNoAssertionsForKotlinFromBinary() { - setUpEnvironment(false, true); - loadSource("noAssertionsForKotlin.kt"); - OutputFileCollection outputFiles = generateClassesInFile(); - javaClassesOutputDirectory = new File(FileUtil.getTempDirectory(), "kotlin-classes"); - OutputUtilsKt.writeAllTo(outputFiles, javaClassesOutputDirectory); - - setUpEnvironment(false, true); - loadSource("noAssertionsForKotlinMain.kt"); - - assertNoIntrinsicsMethodIsCalledInMyClasses(false); - } - - public void testGenerateParamAssertions() throws Exception { - compileJava("doGenerateParamAssertions.java"); - setUpEnvironment(true, false); - - loadSource("doGenerateParamAssertions.kt"); - generateFunction().invoke(null); - } - - public void testDoNotGenerateParamAssertions() { - setUpEnvironment(true, true); - - loadSource("doNotGenerateParamAssertions.kt"); - - assertNoIntrinsicsMethodIsCalled("A", true); - } - - public void testNoParamAssertionForPrivateMethod() { - setUpEnvironment(true, false); - - loadSource("noAssertionForPrivateMethod.kt"); - - assertNoIntrinsicsMethodIsCalled("A", true); - } - - public void testArrayListGet() { - setUpEnvironment(false, false); - - loadSource("arrayListGet.kt"); - String text = generateToText(); - - assertTrue(text.contains("checkExpressionValueIsNotNull")); - assertTrue(text.contains("checkParameterIsNotNull")); - } - - public void testJavaMultipleSubstitutions() { - compileJava("javaMultipleSubstitutions.java"); - setUpEnvironment(false, false); - - loadSource("javaMultipleSubstitutions.kt"); - String text = generateToText(); - - assertEquals(3, StringUtil.getOccurrenceCount(text, "checkExpressionValueIsNotNull")); - assertEquals(3, StringUtil.getOccurrenceCount(text, "checkParameterIsNotNull")); - } - - public void testAssertionForNotNullTypeParam() { - setUpEnvironment(false, false); - - loadSource("assertionForNotNullTypeParam.kt"); - - assertTrue(generateToText().contains("checkParameterIsNotNull")); - } - - public void testNoAssertionForNullableGenericMethod() { - setUpEnvironment(false, true); - - loadSource("noAssertionForNullableGenericMethod.kt"); - - assertNoIntrinsicsMethodIsCalledInMyClasses(true); - } - - public void testNoAssertionForNullableCaptured() { - setUpEnvironment(false, true); - - loadSource("noAssertionForNullableCaptured.kt"); - - assertNoIntrinsicsMethodIsCalledInMyClasses(true); - } - - public void testAssertionForNotNullCaptured() { - setUpEnvironment(false, true); - - loadSource("assertionForNotNullCaptured.kt"); - - assertTrue(generateToText().contains("checkExpressionValueIsNotNull")); - } - - public void testNoAssertionForNullableGenericMethodCall() { - setUpEnvironment(false, true); - - loadSource("noAssertionForNullableGenericMethodCall.kt"); - - assertNoIntrinsicsMethodIsCalled("A", true); - } - - public void testParamAssertionMessage() throws Exception { - setUpEnvironment(false, false); - - loadText("class A { fun foo(s: String) {} }"); - Class a = generateClass("A"); - try { - a.getDeclaredMethod("foo", String.class).invoke(a.newInstance(), new Object[] {null}); - } - catch (InvocationTargetException ite) { - Throwable e = ite.getTargetException(); - //noinspection ThrowableResultOfMethodCallIgnored - assertInstanceOf(e, IllegalArgumentException.class); - assertEquals("Parameter specified as non-null is null: method A.foo, parameter s", e.getMessage()); - return; - } - - fail("Assertion should have been fired"); - } - - private void assertNoIntrinsicsMethodIsCalledInMyClasses(boolean noClassFileIsAnError) { - for (KtFile jetFile : myFiles.getPsiFiles()) { - String fileClassName = JvmFileClassUtil.getFileClassInfoNoResolve(jetFile).getFileClassFqName().asString(); - assertNoIntrinsicsMethodIsCalled(fileClassName, noClassFileIsAnError); - } - } - - private void assertNoIntrinsicsMethodIsCalled(String className, boolean noClassFileIsAnError) { - OutputFileCollection classes = generateClassesInFile(); - OutputFile file = classes.get(className + ".class"); - if (noClassFileIsAnError) { - assertNotNull("File for " + className + " is absent", file); - } - else if (file == null) { - return; - } - ClassReader reader = new ClassReader(file.asByteArray()); - - reader.accept(new ClassVisitor(Opcodes.API_VERSION) { - @Override - public MethodVisitor visitMethod( - int access, @NotNull String callerName, @NotNull String callerDesc, String signature, String[] exceptions - ) { - return new MethodVisitor(Opcodes.API_VERSION) { - @Override - public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { - assertFalse( - "Intrinsics method is called: " + name + desc + " Caller: " + callerName + callerDesc, - "kotlin/jvm/internal/Intrinsics".equals(owner) - ); - } - }; - } - }, 0); + doTestNoAssertionsForKotlinFromBinary("noAssertionsForKotlin.kt", "noAssertionsForKotlinMain.kt"); } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1a64feb078b..c93fc1e189f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13988,6 +13988,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver_lv12.kt"); } + @TestMetadata("paramAssertionMessage.kt") + public void testParamAssertionMessage() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.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/IrBlackBoxAgainstJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxAgainstJavaCodegenTestGenerated.java index 7697f54b4d9..083ee1b6ab3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxAgainstJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxAgainstJavaCodegenTestGenerated.java @@ -442,11 +442,26 @@ public class IrBlackBoxAgainstJavaCodegenTestGenerated extends AbstractIrBlackBo KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxAgainstJava/notNullAssertions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); } + @TestMetadata("callAssertions.kt") + public void testCallAssertions() throws Exception { + runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/callAssertions.kt"); + } + @TestMetadata("delegation.kt") public void testDelegation() throws Exception { runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/delegation.kt"); } + @TestMetadata("doGenerateParamAssertions.kt") + public void testDoGenerateParamAssertions() throws Exception { + runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/doGenerateParamAssertions.kt"); + } + + @TestMetadata("noCallAssertions.kt") + public void testNoCallAssertions() throws Exception { + runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/noCallAssertions.kt"); + } + @TestMetadata("rightElvisOperand.kt") public void testRightElvisOperand() throws Exception { runTest("compiler/testData/codegen/boxAgainstJava/notNullAssertions/rightElvisOperand.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 433f3a52c26..d82f8e4d8a6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -12878,6 +12878,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/nullabilityAssertionOnPrivateMemberExtensionReceiver_lv12.kt"); } + @TestMetadata("paramAssertionMessage.kt") + public void testParamAssertionMessage() throws Exception { + runTest("compiler/testData/codegen/box/javaInterop/notNullAssertions/paramAssertionMessage.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 beab979a176..dfdaefdce18 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -3028,6 +3028,69 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { } } + @TestMetadata("compiler/testData/codegen/bytecodeText/notNullAssertions") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class NotNullAssertions extends AbstractIrBytecodeTextTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInNotNullAssertions() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/notNullAssertions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true); + } + + @TestMetadata("arrayListGet.kt") + public void testArrayListGet() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/arrayListGet.kt"); + } + + @TestMetadata("assertionForNotNullCaptured.kt") + public void testAssertionForNotNullCaptured() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullCaptured.kt"); + } + + @TestMetadata("assertionForNotNullTypeParam.kt") + public void testAssertionForNotNullTypeParam() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/assertionForNotNullTypeParam.kt"); + } + + @TestMetadata("doNotGenerateParamAssertions.kt") + public void testDoNotGenerateParamAssertions() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/doNotGenerateParamAssertions.kt"); + } + + @TestMetadata("javaMultipleSubstitutions.kt") + public void testJavaMultipleSubstitutions() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/javaMultipleSubstitutions.kt"); + } + + @TestMetadata("noAssertionForNullableCaptured.kt") + public void testNoAssertionForNullableCaptured() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableCaptured.kt"); + } + + @TestMetadata("noAssertionForNullableGenericMethod.kt") + public void testNoAssertionForNullableGenericMethod() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethod.kt"); + } + + @TestMetadata("noAssertionForNullableGenericMethodCall.kt") + public void testNoAssertionForNullableGenericMethodCall() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForNullableGenericMethodCall.kt"); + } + + @TestMetadata("noAssertionForPrivateMethod.kt") + public void testNoAssertionForPrivateMethod() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionForPrivateMethod.kt"); + } + + @TestMetadata("noAssertionsForKotlin.kt") + public void testNoAssertionsForKotlin() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/notNullAssertions/noAssertionsForKotlin.kt"); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeText/nullCheckOptimization") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrGenerateNotNullAssertionsTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrGenerateNotNullAssertionsTest.java new file mode 100644 index 00000000000..bfd4e475c6b --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrGenerateNotNullAssertionsTest.java @@ -0,0 +1,22 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen.ir; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.codegen.AbstractGenerateNotNullAssertionsTest; +import org.jetbrains.kotlin.config.CompilerConfiguration; +import org.jetbrains.kotlin.config.JVMConfigurationKeys; + +public class IrGenerateNotNullAssertionsTest extends AbstractGenerateNotNullAssertionsTest { + @Override + public void updateConfiguration(@NotNull CompilerConfiguration configuration) { + configuration.put(JVMConfigurationKeys.IR, true); + } + + public void testNoAssertionsForKotlinFromBinary() { + doTestNoAssertionsForKotlinFromBinary("noAssertionsForKotlin.kt", "noAssertionsForKotlinMain.kt"); + } +}