diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/IrInterpreter.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/IrInterpreter.kt index 1920cf8a406..ace9b30efaf 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/IrInterpreter.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/IrInterpreter.kt @@ -374,7 +374,9 @@ class IrInterpreter(internal val environment: IrInterpreterEnvironment, internal } expression.accessesTopLevelOrObjectField() -> { val propertyOwner = field.correspondingPropertySymbol?.owner - val isConst = propertyOwner?.isConst == true || propertyOwner?.backingField?.initializer?.expression is IrConst<*> + val isConst = propertyOwner?.isConst == true || + propertyOwner?.backingField?.initializer?.expression is IrConst<*> || + propertyOwner?.parentClassOrNull?.hasAnnotation(compileTimeAnnotation) == true // check if object is marked as compile time verify(isConst) { "Cannot interpret get method on top level non const properties" } callStack.addInstruction(CompoundInstruction(field.initializer?.expression)) } diff --git a/compiler/testData/ir/interpreter/object.kt b/compiler/testData/ir/interpreter/object.kt index d4787c912ae..de1b566724b 100644 --- a/compiler/testData/ir/interpreter/object.kt +++ b/compiler/testData/ir/interpreter/object.kt @@ -1,6 +1,6 @@ @CompileTimeCalculation class A { - const val a = { 10 }() + const val a = { 10 }() // lambda is needed to avoid computions by old frontend companion object { const val static = { -10 }() @@ -16,7 +16,7 @@ object ObjectWithConst { const val a = 100 const val b = concat("Value in a: ", a) - val nonConst = "Not const field in compile time object" + val nonConst = { "Not const field in compile time object" }() fun concat(first: String, second: Any) = "$first$second" }