Files
kotlin-fork/compiler/testData/codegen/box/inlineClasses/equalsEvaluationOrderNullableGeneric2.kt
T
2022-02-23 01:23:07 +03:00

36 lines
691 B
Kotlin
Vendored

// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
OPTIONAL_JVM_INLINE_ANNOTATION
value class A<T: Any>(val x: T? = null)
var i = 0
fun set1(): A<Any> {
i = 1
return A()
}
fun test1(n: Int): A<Any> {
if (i != 1)
throw IllegalStateException("Fail $n")
i = 0
return A()
}
fun set1Boxed(): Any? = set1()
fun test1Boxed(n: Int): Any? = test1(n)
fun box(): String {
try {
set1() == test1(1)
set1Boxed() == test1(2)
set1() == test1Boxed(3)
set1Boxed() == test1Boxed(4)
} catch (e: IllegalStateException) {
return e.message ?: "Fail no message"
}
return "OK"
}