Could you please explain why this does not compile...
# getting-started
n
Could you please explain why this does not compile?
Copy code
abstract class BaseClass<BaseType> {

    fun f1(p: BaseType) {}
}

sealed interface IBase<T1, T2> {

    class I1<T1>: IBase<T1, Unit>
}

class InheritedClass<T1, T2>: BaseClass<IBase<T1, T2>>() {

    fun f2() {
        // Compile error:
        // Type mismatch.
        // Required: IBase<T1, T2>
        // Found: IBase.I1<T1>
        f1(IBase.I1<T1>())
    }
}
Thanks.
r
because
IBase.I1<T>
's supertype is
IBase<T1, Unit>
not
IBase<T1, T2>
Since compiler can't prove that
Unit
==
T2
it's a type mismatch Imagine you did this:
Copy code
val test = InheritedClass<String, Int>()
test.f2()
now,
T2
is
Int
which is definitely not
Unit
as you want to assign to it
🙏 1
🤔 1
what exactly are you trying to do?
n
It is an excerpt from a fairly complex code, so I cannot easily explain - probably I over-complicated the generics part of it 🙂 Thanks for your reply.