Files
kotlin-fork/compiler/testData/codegen/box/notNullAssertions/constructorWithMangledParams.kt
T
2022-11-30 18:55:42 +00:00

35 lines
982 B
Kotlin
Vendored

// WITH_REFLECT
// FULL_JDK
// LANGUAGE: +ValueClasses
// TARGET_BACKEND: JVM_IR
import java.lang.NullPointerException
import java.lang.reflect.InvocationTargetException
import kotlin.reflect.jvm.isAccessible
@JvmInline
value class IC(val str: String)
class A(val a: IC, val x : String) {
fun foo() = "$a$x"
private constructor(x: IC) : this(IC(""), "")
}
inline fun assertThrowsExpectedException(block: () -> Unit): Boolean {
try {
block()
} catch (t: Throwable) {
return t is InvocationTargetException && t.targetException is NullPointerException
}
return false
}
fun box(): String {
if (!assertThrowsExpectedException { ::A.call(null, "").foo() }) return "Fail 1"
if (!assertThrowsExpectedException { ::A.call(IC(""), null).foo() }) return "Fail 2"
val privateConstructor = A::class.constructors.single { it.parameters.size == 1 }
privateConstructor.also { it.isAccessible = true }.call(null).foo()
return "OK"
}