Fix codegen box tests for language version 1.4
Since API version 1.4, NullPointerException is thrown for casts of null to any type instead of TypeCastException.
This commit is contained in:
+2
-2
@@ -16,14 +16,14 @@ fun box(): String {
|
||||
try {
|
||||
val i = JImpl().arrayOfNotNull()[0]
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for (i in JImpl().arrayOfNotNull()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
+2
-8
@@ -1,14 +1,8 @@
|
||||
// !LANGUAGE: +StrictJavaNullabilityAssertions
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
// Note: This fails on JVM (non-IR) with a NullPointerException in the loop header. The not-null assertion is not generated when
|
||||
// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and
|
||||
// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters.
|
||||
// The NPE is due to calling `intValue()` on the null Int; it is expected to be asserted as non-null first.
|
||||
|
||||
// FILE: box.kt
|
||||
import kotlin.test.*
|
||||
|
||||
@@ -17,14 +11,14 @@ fun box(): String {
|
||||
try {
|
||||
val i: Int = J.arrayOfMaybeNullable()[0]
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for (i: Int in J.arrayOfMaybeNullable()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -18,14 +18,14 @@ fun box(): String {
|
||||
try {
|
||||
val i = J.listOfNotNull()[0]
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for (i in J.listOfNotNull()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -16,14 +16,14 @@ fun box(): String {
|
||||
try {
|
||||
val i = JImpl().listOfNotNull()[0]
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for (i in JImpl().listOfNotNull()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
+2
-8
@@ -1,14 +1,8 @@
|
||||
// !LANGUAGE: +StrictJavaNullabilityAssertions
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
// Note: This fails on JVM (non-IR) with a NullPointerException in the loop header. The not-null assertion is not generated when
|
||||
// assigning to the loop variable. The root cause seems to be that the loop variable is a KtParameter and
|
||||
// CodegenAnnotatingVisitor/RuntimeAssertionsOnDeclarationBodyChecker do not analyze the need for not-null assertions on KtParameters.
|
||||
// The NPE is due to calling `intValue()` on the null Int; it is expected to be asserted as non-null first.
|
||||
|
||||
// FILE: box.kt
|
||||
import kotlin.test.*
|
||||
|
||||
@@ -17,14 +11,14 @@ fun box(): String {
|
||||
try {
|
||||
val i: Int = J.listOfMaybeNullable()[0]
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for (i: Int in J.listOfMaybeNullable()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -17,14 +17,14 @@ fun box(): String {
|
||||
try {
|
||||
val i = J.listOfNotNull().toTypedArray()[0]
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for (i in J.listOfNotNull().toTypedArray()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -17,14 +17,14 @@ fun box(): String {
|
||||
try {
|
||||
val i = J.iteratorOfNotNull().next()
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for (i in J.iteratorOfNotNull()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -17,14 +17,14 @@ fun box(): String {
|
||||
try {
|
||||
val (index, i) = JImpl().arrayOfNotNull().withIndex().first()
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for ((index, i) in JImpl().arrayOfNotNull().withIndex()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -18,14 +18,14 @@ fun box(): String {
|
||||
try {
|
||||
val (index, i) = J.listOfNotNull().withIndex().first()
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for ((index, i) in J.listOfNotNull().withIndex()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
compiler/testData/codegen/box/ranges/javaInterop/withIndex/javaIteratorOfNotNullWithIndexFailFast.kt
Vendored
+2
-2
@@ -18,14 +18,14 @@ fun box(): String {
|
||||
try {
|
||||
val (index, i) = J.iteratorOfNotNull().withIndex().next()
|
||||
return "Fail: should throw on get()"
|
||||
} catch (e: IllegalStateException) {}
|
||||
} catch (e: NullPointerException) {}
|
||||
|
||||
try {
|
||||
for ((index, i) in J.iteratorOfNotNull().withIndex()) {
|
||||
return "Fail: should throw on get() in loop header"
|
||||
}
|
||||
}
|
||||
catch (e: IllegalStateException) {}
|
||||
catch (e: NullPointerException) {}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user