K2 is too strict with expect/actual And makes thi...
# k2-adopters
a
K2 is too strict with expect/actual And makes this feature hard to use with type aliasing. Below is the explainer Given the following sources • src/commonMain/Promise.kt
Copy code
expect interface Promise<out T>
• src/jvmMain/Promise.kt
Copy code
@file:Suppress(
    "ACTUAL_WITHOUT_EXPECT",
    "ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE"
) 

actual typealias Promise<T> = java.util.concurrent.CompletionStage<T>
Results are as follows a) Without any suppresses, the compilation fails with • 'actual typealias Promise<T> = CompletionStage<T>' has no corresponding expected declaration • The following declaration is incompatible because declaration-site variances of type parameters are different On both kotlin K1 (1.9.21) and K2 (2.0.0-Beta1,2.0.0-Beta2) b) With
@Suppress("ACTUAL_WITHOUT_EXPECT")
The program compiles file on K1 (1.9.21) but fails on K2 (2.0.0-Beta1,2.0.0-Beta2) • Expect declaration
Promise
is incompatible with actual
Promise
because declaration-site variances of type parameters are different c) With
@Suppress("ACTUAL_WITHOUT_EXPECT","ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE")
Results are similar to (b), its like the former suppress directive has no effect at all Now I know the kotlin team doesn't really investigate code with suppresses, but how should we approach this currently?? I can't seem to be able to provide an actual type alias for this. Also, is there a current issue for this?? Or should I file a ticket??
d
cc @bobko
e
There is already an issue for this, which I opened some months ago. https://youtrack.jetbrains.com/issue/KT-61043 Which is also related to https://youtrack.jetbrains.com/issue/KT-21846