Kotlin / dukat

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

Narrowed down property causes compilation failure #335

Open Schahen opened 4 years ago

Schahen commented 4 years ago

Consider following code:

interface Result {}
interface SpecifiedResult extends Result {}

export interface SchedulerLike {
    now: () => Result;
}

export declare class Scheduler implements SchedulerLike {
    now: () => SpecifiedResult;
}

as of now it's converted to:

@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS")

import kotlin.js.*
import kotlin.js.Json
import org.khronos.webgl.*
import org.w3c.dom.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.dom.url.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*

external interface Result

external interface SpecifiedResult : Result

external interface SchedulerLike {
    var now: () -> Result
}

external open class Scheduler : SchedulerLike {
    override var now: () -> SpecifiedResult
}

Which will fail to compile with:

a/b.module_tmp.kt:27:23: error: type of 'now' doesn't match the type of the overridden var-property 'public abstract var now: () -> Result defined in SchedulerLike'
    override var now: () -> SpecifiedResult

Let's discuss what we actually want to do in such case, because as of now I see two options:

1 replace override var now: () -> SpecifiedResult with just var now: () -> Result

2 use val

We should actually thoroughly think through all this stuff - right now I'm not sure what would be a better option and even whether we are limited with only these two options.

trilis commented 4 years ago

This actually happens with all narrowed down types of var-properties, not only lambdas