Avoid object's interpretation with nullable type
#KT-56215 Fixed
This commit is contained in:
+2
-2
@@ -256,11 +256,11 @@ private fun unfoldSetField(expression: IrSetField, callStack: CallStack) {
|
||||
}
|
||||
|
||||
private fun unfoldGetValue(expression: IrGetValue, environment: IrInterpreterEnvironment) {
|
||||
if (expression.isAccessToObject()) {
|
||||
if (expression.isAccessToNotNullableObject()) {
|
||||
// used to evaluate constants inside object
|
||||
// TODO is this correct behaviour?
|
||||
val irGetObject = expression.type.classOrNull?.owner!!.createGetObject()
|
||||
return unfoldGetObjectValue(irGetObject, environment)
|
||||
return unfoldGetObjectValue(irGetObject, environment) // if object already exists, it will be taken from `mapOfObjects`
|
||||
}
|
||||
environment.callStack.pushState(environment.callStack.loadState(expression.symbol))
|
||||
}
|
||||
|
||||
@@ -294,10 +294,10 @@ internal fun IrClass.getSingleAbstractMethod(): IrFunction {
|
||||
return declarations.filterIsInstance<IrSimpleFunction>().single { it.modality == Modality.ABSTRACT }
|
||||
}
|
||||
|
||||
internal fun IrGetValue.isAccessToObject(): Boolean {
|
||||
internal fun IrGetValue.isAccessToNotNullableObject(): Boolean {
|
||||
val owner = this.symbol.owner
|
||||
val expectedClass = this.type.classOrNull?.owner
|
||||
if (expectedClass == null || !expectedClass.isObject) return false
|
||||
if (expectedClass == null || !expectedClass.isObject || this.type.isNullable()) return false
|
||||
return owner.origin == IrDeclarationOrigin.INSTANCE_RECEIVER || owner.name.asString() == "<this>"
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.interpreter.accessesTopLevelOrObjectField
|
||||
import org.jetbrains.kotlin.ir.interpreter.fqName
|
||||
import org.jetbrains.kotlin.ir.interpreter.isAccessToObject
|
||||
import org.jetbrains.kotlin.ir.interpreter.isAccessToNotNullableObject
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.constructors
|
||||
import org.jetbrains.kotlin.ir.util.statements
|
||||
@@ -160,7 +160,7 @@ class IrCompileTimeChecker(
|
||||
}
|
||||
|
||||
override fun visitGetValue(expression: IrGetValue, data: Nothing?): Boolean {
|
||||
return visitedStack.contains(expression.symbol.owner.parent) || expression.isAccessToObject()
|
||||
return visitedStack.contains(expression.symbol.owner.parent) || expression.isAccessToNotNullableObject()
|
||||
}
|
||||
|
||||
override fun visitSetValue(expression: IrSetValue, data: Nothing?): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user