KT-52743 IR: Fix null checks in Elvis operators
This commit is contained in:
committed by
teamcity
parent
ed97e73129
commit
3766698081
+6
@@ -44747,6 +44747,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52580.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52743.kt")
|
||||
public void testKt52743() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52743.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
import org.jetbrains.kotlin.ir.util.hasAnnotation
|
||||
import org.jetbrains.kotlin.ir.util.isTrivial
|
||||
import org.jetbrains.kotlin.ir.util.isConstantLike
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
@@ -121,7 +121,7 @@ class JvmSafeCallChainFoldingLowering(val context: JvmBackendContext) : FileLowe
|
||||
IrConstImpl.boolean(startOffset, endOffset, context.irBuiltIns.booleanType, false)
|
||||
|
||||
private fun irValNotNull(startOffset: Int, endOffset: Int, irVariable: IrVariable): IrExpression =
|
||||
if (irVariable.type.isJvmNullable() || irVariable.initializer?.isTrivial() != true)
|
||||
if (irVariable.type.isJvmNullable() || irVariable.initializer?.isConstantLike != true)
|
||||
IrGetValueImpl(startOffset, endOffset, irVariable.symbol).irEqEqNull().irNot()
|
||||
else
|
||||
irTrue(startOffset, endOffset)
|
||||
|
||||
@@ -596,6 +596,10 @@ fun IrExpression.isTrivial() =
|
||||
this is IrGetObjectValue ||
|
||||
this is IrErrorExpressionImpl
|
||||
|
||||
val IrExpression.isConstantLike: Boolean
|
||||
get() = this is IrConst<*> || this is IrGetSingletonValue
|
||||
|| this is IrGetValue && this.symbol.owner.origin == IrDeclarationOrigin.INSTANCE_RECEIVER
|
||||
|
||||
fun IrExpression.shallowCopy(): IrExpression =
|
||||
shallowCopyOrNull()
|
||||
?: error("Not a copyable expression: ${render()}")
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun <T: Any?> nullableFun(): T {
|
||||
return null as T
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t = nullableFun<String>()
|
||||
return if (t?.length == null) "OK" else "Fail"
|
||||
}
|
||||
+6
@@ -44177,6 +44177,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52580.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52743.kt")
|
||||
public void testKt52743() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52743.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
+6
@@ -44747,6 +44747,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52580.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52743.kt")
|
||||
public void testKt52743() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52743.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
+5
@@ -35687,6 +35687,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52580.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt52743.kt")
|
||||
public void testKt52743() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52743.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/primitive.kt");
|
||||
|
||||
+6
@@ -32491,6 +32491,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52580.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52743.kt")
|
||||
public void testKt52743() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52743.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
+6
@@ -32593,6 +32593,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52580.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52743.kt")
|
||||
public void testKt52743() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52743.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
+5
@@ -29161,6 +29161,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52580.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt52743.kt")
|
||||
public void testKt52743() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52743.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/primitive.kt");
|
||||
|
||||
+6
@@ -35586,6 +35586,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52580.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52743.kt")
|
||||
public void testKt52743() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/safeCall/kt52743.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user