Kotlin / dukat

Converter of <any kind of declarations> to Kotlin external declarations
552 stars 42 forks source link

Optional methods don't convert to nullable lambdas in classes #341

Closed trilis closed 4 years ago

trilis commented 4 years ago

Consider following declarations:

declare interface A {
    f?();
}

declare class B {
    f?();
}

The following code will be generated:

external interface A {
    val f: (() -> Unit)?
        get() = definedExternally
}

external open class B {
    open fun f()
}

As I believe, in classes we should generate the same lambda property.

I think, this distinction is because of distinctions in our parser: methods in classes are parsed as FunctionDeclaration, while methods in interface are parsed as MethodSignatureDeclaration. In fact, our class FunctionDeclaration doesn't even have flag optional.

Schahen commented 4 years ago

I've added better-translation tag since this snippet of code is still compiling - however I'm almost convinced that in some scenarios this can have more dire consequences.