Marcin Wisniowski
01/22/2025, 1:12 PMclass A : B(), C(d), where d is a property inside B. I was assuming that the supertypes are instantiated in order, and so I should have access to B.d by the time I need it for the C constructor, but I am not sure how to express that. Is this possible?ephemient
01/22/2025, 1:37 PMMarcin Wisniowski
01/22/2025, 1:42 PMclass A(
cProvider: () -> C
): B(), C by cProvider()
I want to modify the above code to add a property of B to be an argument of cProvider(). My understanding is that B already exists by the time cProvider() is called.Michael Krussel
01/22/2025, 2:03 PMby. I assume you wouldn't be able to access super either.Sam
01/22/2025, 2:07 PMclass A private constructor(c: C) : B(c), C by c {
constructor(cProvider: () -> C) : this(cProvider())
}Marcin Wisniowski
01/22/2025, 2:13 PMclass A private constructor(c: C) : B(), C by c {
constructor(cProvider: (D) -> C) : this(cProvider(d))
}
Where d is a property inside B. With the extra constructor I can indeed express that, as above, but I get an Cannot access 'd' before the instance has been initialized error, so it doesn't look doable.Sam
01/22/2025, 2:13 PMMichael Krussel
01/22/2025, 2:14 PMby is just syntax sugar for normal delegation, so the solution is to do what it does manually.Marcin Wisniowski
01/22/2025, 2:48 PMby handled before.ephemient
01/23/2025, 2:26 AM