Files
kotlin-fork/compiler/testData/codegen/box/inlineClasses/bridgesWhenInlineClassImplementsGenericInterface.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

37 lines
1015 B
Kotlin
Vendored

// WITH_STDLIB
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@kotlin.jvm.JvmInline
value class InlinedComparable(val x: Int) : Comparable<InlinedComparable> {
override fun compareTo(other: InlinedComparable): Int {
return x.compareTo(other.x)
}
}
fun <T> generic(c: Comparable<T>, element: T) = c.compareTo(element)
interface Base<T> {
fun Base<T>.foo(a: Base<T>, b: T): Base<T>
}
@Suppress("OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE")
@kotlin.jvm.JvmInline
value class InlinedBase(val x: Int) : Base<InlinedBase> {
override fun Base<InlinedBase>.foo(a: Base<InlinedBase>, b: InlinedBase): Base<InlinedBase> {
return if (a is InlinedBase) InlinedBase(a.x + b.x) else this
}
fun double(): InlinedBase {
return this.foo(this, this) as InlinedBase
}
}
fun box(): String {
val a = InlinedComparable(42)
if (generic(a, a) != 0) return "Fail 1"
val b = InlinedBase(3)
if (b.double().x != 6) return "Fail 2"
return "OK"
}