I can't find a solution to this problem
data class Data(val s: String)
sealed class Base<T>(val t: T, val f: Base<T>.() -> Unit)
class A(data: Data, f: A.() -> Unit) : Base<Data>(data, f)
Type mismatch.Required:Base<Data>.() → Unit
Found: A.() → Unit
Please tell me what should be the correct usage
The problem has nothing to do with sealed classes, and nothing to do with generics. It is the same problem as the following:
As you can see from the above simplification of your problem, the reason for the error is that you can't pass a
Subclass.() -> Unit
block to something that expects aBase.() -> Unit
block. If it were possible, then you would be able to callfd
with a block that acts on anInt
butfb
passes it aBigDecimal
instead. So you need to change your class A to: