Skip to content

[K2] Compilation error on overridden declarations #188

@dmitry-stakhov

Description

@dmitry-stakhov

Steps:
1 . Enable k2Mode in Gradle plugin.

nativeCoroutines {
    suffix = "Platform"
    k2Mode = true
}
  1. Add the next code:
import com.rickclephas.kmp.nativecoroutines.NativeCoroutines

interface Base1 {
    @NativeCoroutines
    suspend fun foo()
}

interface Base2 {
    @NativeCoroutines
    suspend fun foo()
}

class Derived1: Base1 {
    @NativeCoroutines
    override suspend fun foo() { println("Derived1") }
}

class Derived2: Base2, Base1 by Derived1() {
    @NativeCoroutines
    override suspend fun foo() { println("Derived2") }
}
  1. Run ./gradlew podPublishDebugXCFramework

Expected: compilation successful

Actual: compilation error

Cannot infer visibility for 'fooPlatform'. Please specify it explicitly.
Class 'Derived2' must override 'fooPlatform' because it inherits multiple interface methods for it.

Note:
If we want to generate Native coroutine overload only to one interface, we get an another error.

interface Base1 {
    @NativeCoroutines
    suspend fun foo()
}

interface Base2 {
    suspend fun foo()
}

class Derived1: Base1 {
    @NativeCoroutines
    override suspend fun foo() {}
}

class Derived2: Base2, Base1 by Derived1() {
    override suspend fun foo() {}
}

Error:

Refined declaration 'suspend fun foo(): Unit' overrides declarations with different or no refinement from:
interface Base2 : Any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions