Files
kotlin-fork/compiler/testData/codegen/box/inlineClasses/checkBoxingOnLocalVariableAssignmentsGeneric.kt
T
2022-02-15 08:11:13 +01:00

61 lines
1.5 KiB
Kotlin
Vendored

// WITH_STDLIB
// WORKS_WHEN_VALUE_CLASS
// LANGUAGE: +ValueClasses, +GenericInlineClassParameter
OPTIONAL_JVM_INLINE_ANNOTATION
value class InlineNotNullPrimitive<T: Int>(val x: T)
OPTIONAL_JVM_INLINE_ANNOTATION
value class InlineNullablePrimitive<T: Int?>(val x: T)
OPTIONAL_JVM_INLINE_ANNOTATION
value class InlineNotNullReference<T: Any>(val a: T)
OPTIONAL_JVM_INLINE_ANNOTATION
value class InlineNullableReference<T>(val a: T)
fun <T: Int> test1(a: InlineNotNullPrimitive<T>) {
val a0 = a
val a1: Any = a // box
val a2: Any? = a // box
val a3: InlineNotNullPrimitive<T> = a
val a4: InlineNotNullPrimitive<T>? = a // box
}
fun <T: Int?> test2(b: InlineNullablePrimitive<T>) {
val b0 = b
val b1: Any = b // box
val b2: Any? = b // box
val b3: InlineNullablePrimitive<T> = b
val b4: InlineNullablePrimitive<T>? = b // box
}
fun <T: Any> test3(c: InlineNotNullReference<T>) {
val c0 = c
val c1: Any = c // box
val c2: Any? = c // box
val c3: InlineNotNullReference<T> = c
val c4: InlineNotNullReference<T>? = c
}
fun <T> test4(d: InlineNullableReference<T>) {
val d0 = d
val d1: Any = d // box
val d2: Any? = d // box
val d3: InlineNullableReference<T> = d
val d4: InlineNullableReference<T>? = d // box
}
fun box(): String {
val a = InlineNotNullPrimitive(1)
val b = InlineNullablePrimitive(1)
val c = InlineNotNullReference("some")
val d = InlineNullableReference("other")
test1(a)
test2(b)
test3(c)
test4(d)
return "OK"
}