[Native] Always cast expression to the expected type after inline

Right now, during the process of inlining, the compiler erases types.
Because of that, we can end up with some random type
(for example, `Any`) where the concrete type was
expected (for example, `Int`). Compiler must insert a cast in the
required places.

#KT-66017 Fixed
This commit is contained in:
Ivan Kylchik
2024-03-06 14:38:17 +01:00
committed by Space Team
parent 555cf56d6d
commit e1180adfbd
27 changed files with 438 additions and 3 deletions
@@ -0,0 +1,15 @@
class A<T>(val prop: T)
inline fun <T> A<T>.process(action: (T) -> Unit) {
action(prop)
}
inline fun acceptInt(p: Int, action: (Int) -> Unit) {
action(p)
}
fun box(): String {
var x = 0
A(1).process { acceptInt(it) { p -> x += p } }
return ('N' + x).toString() + "K"
}
+10
View File
@@ -0,0 +1,10 @@
// WITH_STDLIB
fun box(): String {
listOf(1).forEach { size ->
repeat(size) {
return "OK"
}
}
return "Fail"
}
@@ -0,0 +1,20 @@
// WITH_STDLIB
inline fun <T> Iterable<T>.myForEach(action: (T) -> Unit): Unit {
for (element in this) action(element)
}
inline fun myRepeat(times: Int, action: (Int) -> Unit) {
for (index in 0 until times) {
action(index)
}
}
fun box(): String {
listOf(1).myForEach { size ->
myRepeat(size) {
return "OK"
}
}
return "Fail"
}