Kotlin / dukat

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

Failing to translate expression extensions #404

Closed Schahen closed 2 years ago

Schahen commented 3 years ago

Consider following code:

interface A {}

declare interface AConstructor {
    new(): A;
    ping();
}

declare var Z: AConstructor;
declare class B extends Z {}

It will be translated to:

external interface A

external interface AConstructor {
    fun ping()
}

external var Z: AConstructor

external open class B : Z

Which won't compile, failing with error:

z.module_tmp.kt:25:25: error: unresolved reference: Z
external open class B : Z

This is actually because we don't support extending expressions, as they are described in https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-6.html#extending-expressions

Actually, in the link above nothing is said about variables, but de-facto they are supported as well,

Before fixing https://github.com/Kotlin/dukat/issues/387 we are supposed to do something with this.

The most obvious thing to do is to just substitute Z with AConstructor wherever we encounter it.

Schahen commented 3 years ago

It looks like we expect to have:

external interface A {
   companion object {
       fun ping();
   }
}
external var Z: A;

external open class B : A {
   constructor()
}
JSMonk commented 2 years ago

Fixed in #460