Support inline classes as last expression in lambda
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class Name(private val value: String) {
|
||||
fun asValue(): String = value
|
||||
}
|
||||
|
||||
fun concat(a: Name, b: Name) = a.asValue() + b.asValue()
|
||||
|
||||
inline class UInt(private val value: Int) {
|
||||
fun asValue(): Int = value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val o = inlinedRun {
|
||||
Name("O")
|
||||
}
|
||||
|
||||
val k = notInlinedRun {
|
||||
Name("K")
|
||||
}
|
||||
|
||||
if (concat(o, k) != "OK") return "fail 1"
|
||||
|
||||
val a = UInt(1)
|
||||
val one = inlinedRun {
|
||||
a
|
||||
}
|
||||
|
||||
if (one.asValue() != 1) return "fail 2"
|
||||
|
||||
val b = UInt(2)
|
||||
val two = notInlinedRun {
|
||||
b
|
||||
}
|
||||
|
||||
if (two.asValue() != 2) return "fail 3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
inline fun <R> inlinedRun(block: () -> R): R = block()
|
||||
fun <R> notInlinedRun(block: () -> R): R = block()
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class UInt(private val u: Int)
|
||||
|
||||
fun test(x: UInt?, y: UInt) {
|
||||
val a = run {
|
||||
x!!
|
||||
}
|
||||
|
||||
val b = run {
|
||||
y
|
||||
}
|
||||
}
|
||||
|
||||
// 2 INVOKESTATIC UInt\$Erased.box
|
||||
// 3 INVOKEVIRTUAL UInt.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
Reference in New Issue
Block a user