Support boxing/unboxing for method return types

This commit is contained in:
Mikhail Zarechenskiy
2018-02-05 11:43:10 +03:00
parent 390c214943
commit c5c8d84719
15 changed files with 210 additions and 100 deletions
@@ -0,0 +1,35 @@
// !LANGUAGE: +InlineClasses
inline class Foo(val a: Int) {
fun member(): String = ""
fun asResult() = a
}
fun <T> id(x: T): T = x
fun <T> T.idExtension(): T = this
fun Foo.extension() {}
fun test(f: Foo): String {
id(f) // box
id(f).idExtension() // box
id(f).member() // box unbox
id(f).extension() // box unbox
val a = id(f) // box unbox
val b = id(f).idExtension() // box unbox
if (a.asResult() != 10) return "fail"
if (b.asResult() != 10) return "fail"
return "OK"
}
fun box(): String {
val f = Foo(10)
return test(f)
}
@@ -0,0 +1,28 @@
// !LANGUAGE: +InlineClasses
inline class Foo(val a: Int) {
fun member(): String = ""
}
fun <T> id(x: T): T = x
fun <T> T.idExtension(): T = this
fun Foo.extension() {}
fun test(f: Foo) {
id(f) // box
id(f).idExtension() // box
id(f).member() // box unbox
id(f).extension() // box unbox
val a = id(f) // box unbox
val b = id(f).idExtension() // box unbox
}
// 6 INVOKESTATIC Foo\$Erased.box
// 4 INVOKEVIRTUAL Foo.unbox
// 0 valueOf
// 0 intValue
@@ -0,0 +1,28 @@
// !LANGUAGE: +InlineClasses
inline class Foo(val x: Int) {
fun member() {}
}
fun Foo?.extensionOnNullable() {}
fun test(f: Foo?) {
if (f != null) {
f.member() // unbox
}
if (f != null) {
f.extensionOnNullable()
}
if (f != null) {
val a = f
a.member() // unbox
}
}
// 0 INVOKESTATIC Foo\$Erased.box
// 2 INVOKEVIRTUAL Foo.unbox
// 0 valueOf
// 0 intValue