Files
kotlin-fork/compiler/testData/codegen/box/inlineClasses/kt27096_nullablePrimitive.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

31 lines
1014 B
Kotlin
Vendored

// WITH_STDLIB
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@kotlin.jvm.JvmInline
value class Z1(val x: Int?)
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@kotlin.jvm.JvmInline
value class Z2(val z: Z1)
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@kotlin.jvm.JvmInline
value class ZN(val z: Z1?)
fun wrap1(n: Int): Z1? = if (n < 0) null else Z1(n)
fun wrap2(n: Int): Z2? = if (n < 0) null else Z2(Z1(n))
fun wrapN(n: Int): ZN? = if (n < 0) null else ZN(Z1(n))
fun box(): String {
if (wrap1(-1) != null) throw AssertionError()
if (wrap1(42) == null) throw AssertionError()
if (wrap1(42)!!.x != 42) throw AssertionError()
if (wrap2(-1) != null) throw AssertionError()
if (wrap2(42) == null) throw AssertionError()
if (wrap2(42)!!.z.x != 42) throw AssertionError()
if (wrapN(-1) != null) throw AssertionError()
if (wrapN(42) == null) throw AssertionError()
if (wrapN(42)!!.z!!.x != 42) throw AssertionError()
return "OK"
}