Kotlin / dukat

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

Extending Array without type params leads to generating recursive inheritance #387

Open trilis opened 4 years ago

trilis commented 4 years ago

Minimal example:

declare class Table extends Array {

}

Because Array is known to have one type parameter, there will be generated following declaration inside lib.es5.kt:

external interface Array__0 : Array__0

Which will predictably lead to Stack Overflow when executing getAllParents for this declaration. We shouldn't treat Array without type parameters this way, but work with it according to its lib.es5.d.ts specification:

interface ArrayConstructor {
    new(arrayLength?: number): any[];
    new <T>(arrayLength: number): T[];
    new <T>(...items: T[]): T[];
    (arrayLength?: number): any[];
    <T>(arrayLength: number): T[];
    <T>(...items: T[]): T[];
    isArray(arg: any): arg is any[];
    readonly prototype: any[];
}

declare var Array: ArrayConstructor;

This seems to be the root cause for #234 and #322

trilis commented 4 years ago

Minimal non-stdlib example:

declare interface A<T> {}
declare interface AConstructor {
    new(): A<any>;
}
declare var A: AConstructor;
declare class B extends A {}
trilis commented 4 years ago

Looks like currently we can't generate nothing better than

typealias Table = Array<Any>

But at least it won't crash.

trilis commented 4 years ago

See https://github.com/microsoft/TypeScript/blob/master/lib/lib.es2015.collection.d.ts for other examples.