Files
kotlin-fork/compiler/testData/codegen/box/javaInterop/notNullAssertions/expressionAssertionMessages/backingField.kt
T
Alexander Udalov f01e633f8b JVM: do not put public field access into a single expression block
It affects the `is IrGetField` check in
TypeOperatorLowering.computeNotNullAssertionText, which leads to missing
NPE messages when accessing backing fields of public properties.

 #KT-64615
2024-01-10 11:10:08 +00:00

30 lines
661 B
Kotlin
Vendored

// !LANGUAGE: +NoSourceCodeInNotNullAssertionExceptions
// TARGET_BACKEND: JVM
// FILE: test.kt
val publicProperty = J().s()
private val privateProperty = J().s()
fun f(x: String) = "Fail 1"
fun box(): String {
try {
f(publicProperty)
} catch (e: NullPointerException) {
if (e.message != "publicProperty must not be null") return "Fail 2: ${e.message}"
}
try {
f(privateProperty)
} catch (e: NullPointerException) {
if (e.message != "privateProperty must not be null") return "Fail 3: ${e.message}"
}
return "OK"
}
// FILE: J.java
public class J {
public final String s() { return null; }
}