Files
kotlin-fork/compiler/testData/codegen/boxInline/inlineClasses/unboxGenericParameter/lambda/string.kt
T
Alexander Udalov ad5b6da273 JVM IR: substitute generic type for inline class replacement function calls
The main change here is in `JvmInlineClassLowering.visitFunctionAccess`,
where we now store the substituted return type of the function as the
type of the call expression. Without it, the call could have a
meaningless type, e.g. some `T` which is inaccessible at that place, and
that could backfire in subsequent lowerings in codegen. For example, in
the `stringPlus.kt` test, it would prevent the code in
`FlattenStringConcatenationLowering.isStringPlusCall` from recognizing
and replacing the `String.plus` call, leading to a codegen exception.

Other changes are mostly cosmetics to make the code similar to
`visitFunctionReference`, and preventive optimizations for the case when
the substitution map is empty.
2020-10-28 16:46:28 +01:00

43 lines
850 B
Kotlin
Vendored

// !LANGUAGE: +InlineClasses
// FILE: inline.kt
inline class IC(val value: String) {
inline fun <T> dispatchInline(): T = value as T
}
inline fun <T> IC.extensionInline(): T = value as T
inline fun <T> normalInline(a: IC): T = a.value as T
// FILE: box.kt
// NO_CHECK_LAMBDA_INLINING
fun <T> extension(a: IC): T = bar(a) {
it.extensionInline()
}
fun <T> dispatch(a: IC): T = bar(a) {
it.dispatchInline()
}
fun <T> normal(a: IC): T = bar(a) {
normalInline(it)
}
fun <T, R> bar(value: T, f: (T) -> R): R {
return f(value)
}
fun box(): String {
var res = extension<String>(IC("O")) + "K"
if (res != "OK") return "FAIL 2: $res"
res = dispatch<String>(IC("O")) + "K"
if (res != "OK") return "FAIL 3: $res"
res = normal<String>(IC("O")) + "K"
if (res != "OK") return "FAIL 3: $res"
return "OK"
}