Support inline functions inside inline classes
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class Foo(val x: Int) {
|
||||
inline fun inc(): Foo = Foo(x + 1)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Foo(0)
|
||||
val b = a.inc().inc()
|
||||
|
||||
if (b.x != 2) return "fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline class A(val x: Int) {
|
||||
inline fun inc(): A = A(this.x + 1)
|
||||
|
||||
inline fun result(other: A): String = if (other.x == x) "OK" else "fail"
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun box() : String {
|
||||
val a = A(0)
|
||||
val b = a.inc().inc()
|
||||
val result = b.result(A(2))
|
||||
|
||||
return result
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class Foo(val x: Int) {
|
||||
inline fun inlineInc(): Foo = Foo(x + 1) // one actual call inside wrapper class Foo
|
||||
fun notInlineInc(): Foo = Foo(x + 1)
|
||||
|
||||
fun foo() {
|
||||
inlineInc()
|
||||
}
|
||||
}
|
||||
|
||||
fun test(f: Foo) {
|
||||
f.inlineInc().inlineInc().inlineInc()
|
||||
f.notInlineInc() // one here, one inside wrapper class Foo
|
||||
}
|
||||
|
||||
// 1 INVOKESTATIC Foo\$Erased.inlineInc
|
||||
// 2 INVOKESTATIC Foo\$Erased.notInlineInc
|
||||
Reference in New Issue
Block a user