Allow to interpret non const properties of compile time object
This commit is contained in:
committed by
TeamCityServer
parent
1978bfcd85
commit
295638b26e
@@ -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))
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
@CompileTimeCalculation
|
||||
class A {
|
||||
const val a = <!EVALUATED: `10`!>{ 10 }()<!>
|
||||
const val a = <!EVALUATED: `10`!>{ 10 }()<!> // lambda is needed to avoid computions by old frontend
|
||||
|
||||
companion object {
|
||||
const val static = <!EVALUATED: `-10`!>{ -10 }()<!>
|
||||
@@ -16,7 +16,7 @@ object ObjectWithConst {
|
||||
const val a = 100
|
||||
const val b = <!EVALUATED: `Value in a: 100`!>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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user