JVM_IR: IC: Unbox inline class argument of callable reference

if it is unbound and the underlying type is reference type.
If the underlying type is primitive, it is boxed and unboxed
correctly, otherwise, it is simply casted and not unboxed.
Additionally, generate functions for inliner with inline classes
in signature, so unboxing works.
The unboxing is removed after inlining.
 #KT-44722 Fixed
This commit is contained in:
Ilmir Usmanov
2021-02-16 09:24:49 +01:00
parent 744a0fcd25
commit 741c1a864f
19 changed files with 604 additions and 9 deletions
@@ -0,0 +1,22 @@
inline class Value(val value: Any)
object Foo {
fun foo(value: Value) {
res = value.value as String
}
fun bar(value: Value?) {
res = value?.value as String
}
}
var res = "FAIL"
fun box(): String {
Value("OK").let(Foo::foo)
if (res != "OK") return "FAIL 1: $res"
res = "FAIL"
Value("OK").let(Foo::bar)
return res
}
@@ -0,0 +1,22 @@
inline class Value(val value: Any?)
object Foo {
fun foo(value: Value) {
res = value.value as String
}
fun bar(value: Value?) {
res = value?.value as String
}
}
var res = "FAIL"
fun box(): String {
Value("OK").let(Foo::foo)
if (res != "OK") return "FAIL 1: $res"
res = "FAIL"
Value("OK").let(Foo::bar)
return res
}
@@ -0,0 +1,24 @@
inline class Value(val value: Int)
object Foo {
fun foo(value: Value) {
res = value.value
}
fun bar(value: Value?) {
res = value?.value!!
}
}
var res = 0
fun box(): String {
Value(42).let(Foo::foo)
if (res != 42) return "FAIL 1 $res"
res = 0
Value(42).let(Foo::bar)
if (res != 42) return "FAIL 2 $res"
return "OK"
}
@@ -0,0 +1,24 @@
inline class Value(val value: Int?)
object Foo {
fun foo(value: Value) {
res = value.value!!
}
fun bar(value: Value?) {
res = value?.value!!
}
}
var res = 0
fun box(): String {
Value(42).let(Foo::foo)
if (res != 42) return "FAIL 1 $res"
res = 0
Value(42).let(Foo::bar)
if (res != 42) return "FAIL 2 $res"
return "OK"
}
@@ -0,0 +1,23 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
object Foo {
fun foo(result: Result<String>) {
res = result.getOrNull()!!
}
fun bar(result: Result<String>?) {
res = result?.getOrNull()!!
}
}
var res = "FAIL"
fun box(): String {
Result.success("OK").let(Foo::foo)
if (res != "OK") return "FAIL 1 $res"
res = "FAIL"
Result.success("OK").let(Foo::bar)
return res
}
@@ -0,0 +1,22 @@
inline class Value(val value: String)
object Foo {
fun foo(value: Value) {
res = value.value
}
fun bar(value: Value?) {
res = value?.value!!
}
}
var res = "FAIL"
fun box(): String {
Value("OK").let(Foo::foo)
if (res != "OK") return "FAIL 1: $res"
res = "FAIL"
Value("OK").let(Foo::bar)
return res
}
@@ -0,0 +1,22 @@
inline class Value(val value: String?)
object Foo {
fun foo(value: Value) {
res = value.value!!
}
fun bar(value: Value?) {
res = value?.value!!
}
}
var res = "FAIL"
fun box(): String {
Value("OK").let(Foo::foo)
if (res != "OK") return "FAIL 1: $res"
res = "FAIL"
Value("OK").let(Foo::bar)
return res
}