Closed kitakkun closed 3 days ago
Throwing the error makes it difficult to fall back to superclass methods.
The inside of the generated method (current implementation):
@BackInTime
class SubClass : SuperClass(), BackInTimeDebuggable {
override fun forceSetValue(propertyName: String, value: Any?) {
when (propertyName) {
"prop1" -> { /* set value to prop1 */ }
"prop2" -> { /* set value to prop2 */ }
"prop3" -> { /* set value to prop3 */ }
else -> error()
}
}
}
This should be...
@BackInTime
class SubClass : SuperClass(), BackInTimeDebuggable {
override fun forceSetValue(propertyName: String, value: Any?) {
when (propertyName) {
"prop1" -> { /* set value to prop1 */ }
"prop2" -> { /* set value to prop2 */ }
"prop3" -> { /* set value to prop3 */ }
else -> super.forceSetValue(propertyName, value) // Should call super method because SuperClass is also BackInTimeDebuggable.
}
}
}
BTW, I don't know how to call super declarations. I couldn't find anything like irSuper
though there's irThis
.
I must investigate how super
is represented at the IR level.
I found the function named getLastOverridden
...! This might be useful for this use case.
fun IrFunction.getLastOverridden(): IrFunction {
if (this !is IrSimpleFunction) return this
return generateSequence(listOf(this)) { it.firstOrNull()?.overriddenSymbols?.map { it.owner } }.flatten().last()
}
Oops, getLastOverriden
seems to return the function at the most base class. I mean, it always returns the declaration inside BackInTimeDebuggable
interface.
What we want is the nearest overridden symbol.
Maybe we can get the implementation inside the superclass like this:
val superDeclaration = declaration.overriddenSymbols.firstOrNull { it.owner.modality == Modality.OPEN }
The other functions like serializeValue
and deserializeValue
have the same problem.
Example: