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
45 lines
1.2 KiB
Kotlin
Vendored
45 lines
1.2 KiB
Kotlin
Vendored
// DONT_TARGET_EXACT_BACKEND: WASM
|
|
// WASM_MUTE_REASON: SAM_CONVERSIONS
|
|
// !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
|
|
|
|
// This test should check argument coercion between the SAM and the lambda.
|
|
// For now it checks that Char is boxed in JS
|
|
|
|
fun interface CharToAny {
|
|
fun invoke(c: Char): Any
|
|
}
|
|
|
|
fun interface GenericToAny<T> {
|
|
fun invoke(t: T): Any
|
|
}
|
|
|
|
fun interface GenericCharToAny: GenericToAny<Char>
|
|
|
|
fun foo1(c: CharToAny): Any = c.invoke('1')
|
|
|
|
fun <T> foo2(t: T, g: GenericToAny<T>): Any = g.invoke(t)
|
|
|
|
fun foo3(c: GenericCharToAny) = c.invoke('3')
|
|
|
|
fun box(): String {
|
|
|
|
val c1 = foo1 { it }
|
|
if (c1 !is Char || c1 != '1') return "fail1"
|
|
|
|
val c2 = foo2<Char>('2') { it }
|
|
if (c2 !is Char || c2 != '2') return "fail2"
|
|
|
|
val c3 = foo3 { it }
|
|
if (c3 !is Char || c3 != '3') return "fail3"
|
|
|
|
val c4 = CharToAny { it }.invoke('4')
|
|
if (c4 !is Char || c4 != '4') return "fail4"
|
|
|
|
val c5 = GenericToAny<Char> { it }.invoke('5')
|
|
if (c5 !is Char || c5 != '5') return "fail5"
|
|
|
|
val c6 = GenericCharToAny { it }.invoke('6')
|
|
if (c6 !is Char || c6 != '6') return "fail6"
|
|
|
|
return "OK"
|
|
} |