diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/Utils.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/Utils.kt index db4250e7d92..9aa9508a513 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/Utils.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/Utils.kt @@ -211,6 +211,11 @@ internal fun IrFieldAccessExpression.accessesTopLevelOrObjectField(): Boolean { return this.receiver == null || (this.receiver?.type?.classifierOrNull?.owner as? IrClass)?.isObject == true } +internal fun IrClass.getOriginalPropertyByName(name: String): IrProperty { + val property = this.declarations.single { it.nameForIrSerialization.asString() == name } as IrProperty + return (property.getter!!.getLastOverridden() as IrSimpleFunction).correspondingPropertySymbol!!.owner +} + internal fun IrFunctionAccessExpression.getFunctionThatContainsDefaults(): IrFunction { val irFunction = this.symbol.owner fun IrValueParameter.lookup(): IrFunction? { diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/intrinsics/IntrinsicImplementations.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/intrinsics/IntrinsicImplementations.kt index f67ba72bee5..a7ec858aa08 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/intrinsics/IntrinsicImplementations.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/intrinsics/IntrinsicImplementations.kt @@ -20,7 +20,6 @@ import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.impl.buildSimpleType import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable -import org.jetbrains.kotlin.ir.util.resolveFakeOverride import org.jetbrains.kotlin.types.Variance import java.util.* @@ -168,11 +167,9 @@ internal object EnumIntrinsics : IntrinsicBase() { callStack.pushState(enumEntry.getField(symbol)!!) } "compareTo" -> { - val ordinal = enumEntry.irClass.declarations.filterIsInstance() - .first { it.name.asString() == "ordinal" } - .resolveFakeOverride()!! + val ordinalSymbol = enumEntry.irClass.getOriginalPropertyByName("ordinal").symbol val other = callStack.getState(irFunction.valueParameters.single().symbol) - val compareTo = enumEntry.getField(ordinal.symbol)!!.asInt().compareTo(other.getField(ordinal.symbol)!!.asInt()) + val compareTo = enumEntry.getField(ordinalSymbol)!!.asInt().compareTo(other.getField(ordinalSymbol)!!.asInt()) callStack.pushState(compareTo.toState(irFunction.returnType)) } // TODO "clone" -> throw exception @@ -182,10 +179,8 @@ internal object EnumIntrinsics : IntrinsicBase() { } "hashCode" -> callStack.pushState(enumEntry.hashCode().toState(irFunction.returnType)) "toString" -> { - val name = enumEntry.irClass.declarations.filterIsInstance() - .first { it.name.asString() == "name" } - .resolveFakeOverride()!! - callStack.pushState(enumEntry.getField(name.symbol)!!) + val nameSymbol = enumEntry.irClass.getOriginalPropertyByName("name").symbol + callStack.pushState(enumEntry.getField(nameSymbol)!!) } "values" -> EnumValues.evaluate(irFunction, environment) "valueOf" -> EnumValueOf.evaluate(irFunction, environment) diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/state/ExceptionState.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/state/ExceptionState.kt index d49788eac0b..e057959f084 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/state/ExceptionState.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/state/ExceptionState.kt @@ -6,13 +6,10 @@ package org.jetbrains.kotlin.ir.interpreter.state import org.jetbrains.kotlin.ir.declarations.IrClass -import org.jetbrains.kotlin.ir.declarations.IrProperty -import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction -import org.jetbrains.kotlin.ir.interpreter.getLastOverridden +import org.jetbrains.kotlin.ir.interpreter.getOriginalPropertyByName import org.jetbrains.kotlin.ir.interpreter.stack.Variable import org.jetbrains.kotlin.ir.interpreter.toState import org.jetbrains.kotlin.ir.util.isSubclassOf -import org.jetbrains.kotlin.ir.util.nameForIrSerialization import kotlin.math.min internal class ExceptionState private constructor( @@ -29,8 +26,8 @@ internal class ExceptionState private constructor( private lateinit var exceptionFqName: String private val exceptionHierarchy = mutableListOf() - private val messageProperty = irClass.getPropertyByName("message") - private val causeProperty = irClass.getPropertyByName("cause") + private val messageProperty = irClass.getOriginalPropertyByName("message") + private val causeProperty = irClass.getOriginalPropertyByName("cause") private val stackTrace: List = stackTrace.reversed() @@ -103,14 +100,9 @@ internal class ExceptionState private constructor( override fun toString(): String = message?.let { "$exceptionFqName: $it" } ?: exceptionFqName companion object { - private fun IrClass.getPropertyByName(name: String): IrProperty { - val property = this.declarations.single { it.nameForIrSerialization.asString() == name } as IrProperty - return (property.getter!!.getLastOverridden() as IrSimpleFunction).correspondingPropertySymbol!!.owner - } - private fun evaluateFields(exception: Throwable, irClass: IrClass, stackTrace: List): MutableList { - val messageProperty = irClass.getPropertyByName("message") - val causeProperty = irClass.getPropertyByName("cause") + val messageProperty = irClass.getOriginalPropertyByName("message") + val causeProperty = irClass.getOriginalPropertyByName("cause") val messageVar = Variable(messageProperty.symbol, exception.message.toState(messageProperty.getter!!.returnType)) val causeVar = exception.cause?.let { diff --git a/compiler/testData/ir/interpreter/enums1.kt b/compiler/testData/ir/interpreter/enums1.kt index 31adb4700e9..b1a518fd548 100644 --- a/compiler/testData/ir/interpreter/enums1.kt +++ b/compiler/testData/ir/interpreter/enums1.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR import kotlin.* import kotlin.collections.*