Norbi
02/04/2023, 8:20 PMabstract 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.Roukanken
02/04/2023, 8:30 PMIBase.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:
val test = InheritedClass<String, Int>()
test.f2()
now, T2
is Int
which is definitely not Unit
as you want to assign to itNorbi
02/04/2023, 8:49 PM