ad5b6da273
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.
50 lines
1.2 KiB
Kotlin
Vendored
50 lines
1.2 KiB
Kotlin
Vendored
// !LANGUAGE: +InlineClasses
|
|
|
|
fun <T> underlying(a: IC): T = bar(a, object : IFace<IC, T> {
|
|
override fun call(ic: IC): T = ic.value as T
|
|
})
|
|
|
|
fun <T> extension(a: IC): T = bar(a, object : IFace<IC, T> {
|
|
override fun call(ic: IC): T = ic.extensionValue()
|
|
})
|
|
|
|
fun <T> dispatch(a: IC): T = bar(a, object : IFace<IC, T> {
|
|
override fun call(ic: IC): T = ic.dispatchValue()
|
|
})
|
|
|
|
fun <T> normal(a: IC): T = bar(a, object : IFace<IC, T> {
|
|
override fun call(ic: IC): T = normalValue(ic)
|
|
})
|
|
|
|
interface IFace<T, R> {
|
|
fun call(ic: T): R
|
|
}
|
|
|
|
fun <T, R> bar(value: T, f: IFace<T, R>): R {
|
|
return f.call(value)
|
|
}
|
|
|
|
fun <T> IC.extensionValue(): T = value as T
|
|
|
|
fun <T> normalValue(ic: IC): T = ic.value as T
|
|
|
|
inline class IC(val value: String) {
|
|
fun <T> dispatchValue(): T = value as T
|
|
}
|
|
|
|
fun box(): String {
|
|
var res = underlying<String>(IC("O")) + "K"
|
|
if (res != "OK") return "FAIL 1: $res"
|
|
|
|
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"
|
|
}
|