Make enum entries to be interpreted in right order

#KT-53727 Fixed
This commit is contained in:
Ivan Kylchik
2022-07-22 15:24:33 +02:00
committed by teamcity
parent 76f1744868
commit 008a5f02e5
5 changed files with 20 additions and 2 deletions
@@ -259,7 +259,7 @@ private fun unfoldGetEnumValue(expression: IrGetEnumValue, environment: IrInterp
callStack.pushSimpleInstruction(expression)
val enumEntry = expression.symbol.owner
val enumClass = enumEntry.symbol.owner.parentAsClass
enumClass.declarations.filterIsInstance<IrEnumEntry>().forEach {
enumClass.declarations.filterIsInstance<IrEnumEntry>().reversed().forEach {
callStack.pushSimpleInstruction(it)
}
}
@@ -398,6 +398,7 @@ class IrInterpreter(internal val environment: IrInterpreterEnvironment, internal
?: (enumInitializer as IrBlock).statements.filterIsInstance<IrEnumConstructorCall>().single()
val enumSuperCall = enumConstructorCall.getSuperEnumCall()
// TODO must call this function even after exception has occurred or else data will be corrupted
val cleanEnumSuperCall = fun() {
enumSuperCall.apply { (0 until this.valueArgumentsCount).forEach { putValueArgument(it, null) } } // restore to null
callStack.popState() // result of constructor must be dropped, because next instruction will be `IrGetEnumValue`
@@ -37,7 +37,7 @@ class IrConstTransformer(
onError(original, this)
return when (mode) {
// need to pass any const value to be able to get some bytecode and then report error
EvaluationMode.ONLY_INTRINSIC_CONST -> IrConstImpl.int(startOffset, endOffset, type, 0)
EvaluationMode.ONLY_INTRINSIC_CONST -> IrConstImpl.constNull(startOffset, endOffset, type)
else -> original
}
}