Avoid object's interpretation with nullable type
#KT-56215 Fixed
This commit is contained in:
+6
@@ -28259,6 +28259,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceNameFromStaticInDifferentModule.kt")
|
||||
public void testReferenceNameFromStaticInDifferentModule() throws Exception {
|
||||
|
||||
+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 {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
object ObjectWithExtension
|
||||
|
||||
fun ObjectWithExtension?.nullableExtensionFun(): String =
|
||||
if(this == null)
|
||||
"Null"
|
||||
else
|
||||
"Not null"
|
||||
|
||||
fun ObjectWithExtension.extensionFun(): String =
|
||||
if(this == null)
|
||||
"Null" // unreachable branch, will be optimized by interpreter
|
||||
else
|
||||
"Not null"
|
||||
|
||||
fun box(): String {
|
||||
val nullObjectWithExtension: ObjectWithExtension? = null
|
||||
if ("${nullObjectWithExtension.nullableExtensionFun()}" != "Null") return "Fail 1"
|
||||
if ("${ObjectWithExtension.nullableExtensionFun()}" != "Not null") return "Fail 2"
|
||||
|
||||
if ("${ObjectWithExtension.extensionFun()}" != "Not null") return "Fail 3"
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -27149,6 +27149,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+6
@@ -28259,6 +28259,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("referenceNameFromStaticInDifferentModule.kt")
|
||||
public void testReferenceNameFromStaticInDifferentModule() throws Exception {
|
||||
|
||||
+5
@@ -22887,6 +22887,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+6
@@ -20977,6 +20977,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+6
@@ -20995,6 +20995,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+6
@@ -20995,6 +20995,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+6
@@ -20995,6 +20995,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+6
@@ -23954,6 +23954,12 @@ public class K2NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTes
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+6
@@ -23720,6 +23720,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
Generated
+5
@@ -18635,6 +18635,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt56215.kt")
|
||||
public void testKt56215() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt56215.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/involvesIrInterpreter/dumpIrAndCheck")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user