b6ad1584c9
- Use typed Wasm tables for each interface method to avoid runtime function type check - Use linear search by implemented interface rather than by individual virtual function signature
52 lines
1.0 KiB
Kotlin
Vendored
52 lines
1.0 KiB
Kotlin
Vendored
// DONT_TARGET_EXACT_BACKEND: WASM
|
|
// WASM_MUTE_REASON: SAM_CONVERSIONS
|
|
// !LANGUAGE: +InlineClasses
|
|
|
|
fun <T> underlying(a: IC): T = bar(a) {
|
|
it.value as T
|
|
}
|
|
|
|
fun <T> extension(a: IC): T = bar(a) {
|
|
it.extensionValue()
|
|
}
|
|
|
|
fun <T> dispatch(a: IC): T = bar(a) {
|
|
it.dispatchValue()
|
|
}
|
|
|
|
fun <T> normal(a: IC): T = bar(a) {
|
|
normalValue(it)
|
|
}
|
|
|
|
fun interface FunIFace<T, R> {
|
|
fun call(ic: T): R
|
|
}
|
|
|
|
fun <T, R> bar(value: T, f: FunIFace<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"
|
|
}
|