Skip to content

Maybe support overridden declaration? #195

@oscarthecat

Description

@oscarthecat

hi, we have a problem when apply NativeCoroutines, we currently use ksp with k2mode=false to generated code. we found @NativeCoroutines can not be applied to the subclass, but must be applied to the parent class or interface

Currently, when it is applied to the parent class or interface, it only generates the corresponding method in the parent class or inferface. For example, for the following classes:

interface Store<STATE, EVENT> {
    val state: Flow<STATE>
    suspend fun dispatch(action: EVENT)
}

class FooState
class FooEvent
class FooStore : Store<FooState, FooEvent> {
    override val state: Flow<FooState>
        get() = TODO("Not yet implemented")
    override suspend fun dispatch(action: FooEvent) {
        TODO("Not yet implemented")
    }
}

class BarState
class BarEvent
class BarStore : Store<BarState, BarEvent> {
    override val state: Flow<BarState>
        get() = TODO("Not yet implemented")
    override suspend fun dispatch(action: BarEvent) {
        TODO("Not yet implemented")
    }
}

if we add @NativeCoroutines annatations to interface

interface Store<STATE, EVENT> {
    @NativeCoroutines
    val state: Flow<STATE>
    @NativeCoroutines
    suspend fun dispatch(action: EVENT)
}

the generated code will be

@ObjCName(name = "state")
public val <STATE, EVENT> Store<STATE, EVENT>.stateNative: NativeFlow<STATE>
  get() = state.asNativeFlow(null)

@ObjCName(name = "dispatch")
public fun <STATE, EVENT> Store<STATE, EVENT>.dispatchNative(action: EVENT): NativeSuspend<Unit> =
    nativeSuspend(null) { dispatch(action) }

and in bin framework header we have

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("FooNativeKt")))
@interface NCSSFooNativeKt : NCSSBase
+ (NCSSKotlinUnit *(^(^)(NCSSKotlinUnit *(^)(id _Nullable, NCSSKotlinUnit *(^)(void), NCSSKotlinUnit *), NCSSKotlinUnit *(^)(NSError * _Nullable, NCSSKotlinUnit *), NCSSKotlinUnit *(^)(NSError *, NCSSKotlinUnit *)))(void))state:(id<NCSSStore>)receiver __attribute__((swift_name("state(_:)")));
+ (NCSSKotlinUnit *(^(^)(NCSSKotlinUnit *(^)(NCSSKotlinUnit *, NCSSKotlinUnit *), NCSSKotlinUnit *(^)(NSError *, NCSSKotlinUnit *), NCSSKotlinUnit *(^)(NSError *, NCSSKotlinUnit *)))(void))dispatch:(id<NCSSStore>)receiver action:(id _Nullable)action __attribute__((swift_name("dispatch(_:action:)")));
@end

but we expect generated code to be

@ObjCName(name = "state")
public val FooStore.stateNative: NativeFlow<FooState>
  get() = state.asNativeFlow(null)

@ObjCName(name = "dispatch")
public fun FooStore.dispatchNative(action: FooEvent): NativeSuspend<Unit> = nativeSuspend(null) {
    dispatch(action) }

and in bin framework header

@interface NCSSFooStore (Extensions)
- (NCSSKotlinUnit *(^(^)(NCSSKotlinUnit *(^)(NCSSKotlinUnit *, NCSSKotlinUnit *), NCSSKotlinUnit *(^)(NSError *, NCSSKotlinUnit *), NCSSKotlinUnit *(^)(NSError *, NCSSKotlinUnit *)))(void))dispatchAction:(NCSSFooEvent *)action __attribute__((swift_name("dispatch(action:)")));
@property (readonly) NCSSKotlinUnit *(^(^state)(NCSSKotlinUnit *(^)(NCSSFooState *, NCSSKotlinUnit *(^)(void), NCSSKotlinUnit *), NCSSKotlinUnit *(^)(NSError * _Nullable, NCSSKotlinUnit *), NCSSKotlinUnit *(^)(NSError *, NCSSKotlinUnit *)))(void) __attribute__((swift_name("state")));
@end

just for FooStore, not BarStore, any way except modify kmp-nativecoroutines-ksp can do this? thank you very much!

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