PSI2IR KT-44855 propagate smart cast information for property values

This commit is contained in:
Dmitry Petrov
2021-07-29 15:30:07 +03:00
committed by teamcityserver
parent cdbd0eb932
commit ca5ebdc13c
12 changed files with 322 additions and 5 deletions
@@ -41421,6 +41421,18 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("kt44855.kt")
public void testKt44855() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt44855.kt");
}
@Test
@TestMetadata("kt44855a.kt")
public void testKt44855a() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt44855a.kt");
}
@Test
@TestMetadata("kt46578_anonObject.kt")
public void testKt46578_anonObject() throws Exception {
@@ -2484,6 +2484,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/regressions/kt24114.kt");
}
@Test
@TestMetadata("kt44855.kt")
public void testKt44855() throws Exception {
runTest("compiler/testData/ir/irText/regressions/kt44855.kt");
}
@Test
@TestMetadata("kt45236.kt")
public void testKt45236() throws Exception {
@@ -88,19 +88,23 @@ class CallGenerator(statementGenerator: StatementGenerator) : StatementGenerator
descriptor: DeclarationDescriptor,
resolvedCall: ResolvedCall<*>?,
origin: IrStatementOrigin?,
irType: IrType? = null
smartCastIrType: IrType? = null
): IrExpression =
when (descriptor) {
is FakeCallableDescriptorForObject ->
generateValueReference(startOffset, endOffset, descriptor.getReferencedDescriptor(), resolvedCall, origin, irType)
generateValueReference(startOffset, endOffset, descriptor.getReferencedDescriptor(), resolvedCall, origin, smartCastIrType)
is TypeAliasDescriptor ->
generateValueReference(startOffset, endOffset, descriptor.classDescriptor!!, null, origin, irType)
generateValueReference(startOffset, endOffset, descriptor.classDescriptor!!, null, origin, smartCastIrType)
is ClassDescriptor -> {
val classValueType = descriptor.classValueType!!
statementGenerator.generateSingletonReference(descriptor, startOffset, endOffset, classValueType)
}
is PropertyDescriptor -> {
generateCall(startOffset, endOffset, statementGenerator.pregenerateCall(resolvedCall!!))
val irCall = generateCall(startOffset, endOffset, statementGenerator.pregenerateCall(resolvedCall!!))
if (smartCastIrType != null)
IrTypeOperatorCallImpl(startOffset, endOffset, smartCastIrType, IrTypeOperator.IMPLICIT_CAST, smartCastIrType, irCall)
else
irCall
}
is SyntheticFieldDescriptor -> {
val receiver = statementGenerator.generateBackingFieldReceiver(startOffset, endOffset, resolvedCall, descriptor)
@@ -109,7 +113,7 @@ class CallGenerator(statementGenerator: StatementGenerator) : StatementGenerator
IrGetFieldImpl(startOffset, endOffset, field, fieldType, receiver?.load())
}
is VariableDescriptor ->
generateGetVariable(startOffset, endOffset, descriptor, getTypeArguments(resolvedCall), origin, irType)
generateGetVariable(startOffset, endOffset, descriptor, getTypeArguments(resolvedCall), origin, smartCastIrType)
else ->
TODO("Unexpected callable descriptor: $descriptor ${descriptor::class.java.simpleName}")
}
@@ -0,0 +1,38 @@
// IGNORE_BACKEND: JVM
// TARGET_BACKEND: JVM
// MODULE: lib
// FILE: test/Parent.java
package test;
public class Parent {
protected String qqq = "";
public String getQqq() {
return qqq;
}
}
// MODULE: main(lib)
// FILE: kt44855.kt
import test.Parent
open class Child(val x: Parent?) : Parent() {
inner class QQQ {
fun z() {
x as Child
val q = x.qqq
x.qqq = q + "OK"
}
}
}
fun box(): String {
val cc = Child(null)
val c = Child(cc)
val d = c.QQQ()
d.z()
return cc.qqq
}
@@ -0,0 +1,41 @@
// TARGET_BACKEND: JVM
// MODULE: lib
// FILE: test/Parent.java
package test;
public class Parent {
private String qqq = "";
protected void setQqq(String q) {
this.qqq = q;
}
public String getQqq() {
return qqq;
}
}
// MODULE: main(lib)
// FILE: kt44855.kt
import test.Parent
open class Child(val x: Parent?) : Parent() {
inner class QQQ {
fun z() {
x as Child
val q = x.qqq
x.qqq = q + "OK"
}
}
}
fun box(): String {
val cc = Child(null)
val c = Child(cc)
val d = c.QQQ()
d.z()
return cc.qqq
}
+75
View File
@@ -0,0 +1,75 @@
FILE fqName:<root> fileName:/kt44855.kt
CLASS CLASS name:Child modality:OPEN visibility:public superTypes:[<root>.Parent]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Child
CONSTRUCTOR visibility:public <> (x:<root>.Parent?) returnType:<root>.Child [primary]
VALUE_PARAMETER name:x index:0 type:<root>.Parent?
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Parent'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Child modality:OPEN visibility:public superTypes:[<root>.Parent]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:<root>.Parent? visibility:private [final]
EXPRESSION_BODY
GET_VAR 'x: <root>.Parent? declared in <root>.Child.<init>' type=<root>.Parent? origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:<root>.Child) returnType:<root>.Parent?
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Child
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-x> (): <root>.Parent? declared in <root>.Child'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:<root>.Parent? visibility:private [final]' type=<root>.Parent? origin=null
receiver: GET_VAR '<this>: <root>.Child declared in <root>.Child.<get-x>' type=<root>.Child origin=null
CLASS CLASS name:QQQ modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Child.QQQ
CONSTRUCTOR visibility:public <> ($this:<root>.Child) returnType:<root>.Child.QQQ [primary]
$outer: VALUE_PARAMETER name:<this> type:<root>.Child
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:QQQ modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]'
FUN name:z visibility:public modality:FINAL <> ($this:<root>.Child.QQQ) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.Child.QQQ
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
TYPE_OP type=<root>.Child origin=CAST typeOperand=<root>.Child
CALL 'public final fun <get-x> (): <root>.Parent? declared in <root>.Child' type=<root>.Parent? origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Child declared in <root>.Child' type=<root>.Child origin=null
VAR name:q type:@[FlexibleNullability] kotlin.String? [val]
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:qqq type:@[FlexibleNullability] kotlin.String? visibility:protected/*protected and package*/' type=@[FlexibleNullability] kotlin.String? origin=GET_PROPERTY
receiver: TYPE_OP type=<root>.Child origin=IMPLICIT_CAST typeOperand=<root>.Child
CALL 'public final fun <get-x> (): <root>.Parent? declared in <root>.Child' type=<root>.Parent? origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Child declared in <root>.Child' type=<root>.Child origin=null
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:qqq type:@[FlexibleNullability] kotlin.String? visibility:protected/*protected and package*/' type=kotlin.Unit origin=EQ
receiver: TYPE_OP type=<root>.Child origin=IMPLICIT_CAST typeOperand=<root>.Child
CALL 'public final fun <get-x> (): <root>.Parent? declared in <root>.Child' type=<root>.Parent? origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Child declared in <root>.Child' type=<root>.Child origin=null
value: CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=PLUS
$this: GET_VAR 'val q: @[FlexibleNullability] kotlin.String? [val] declared in <root>.Child.QQQ.z' type=@[FlexibleNullability] kotlin.String? origin=null
other: CONST String type=kotlin.String value="OK"
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:getQqq visibility:public modality:OPEN <> ($this:<root>.Parent) returnType:@[FlexibleNullability] kotlin.String? [fake_override]
overridden:
public open fun getQqq (): @[FlexibleNullability] kotlin.String? declared in <root>.Parent
$this: VALUE_PARAMETER name:<this> type:<root>.Parent
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.Parent
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.Parent
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.Parent
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
+22
View File
@@ -0,0 +1,22 @@
// TARGET_BACKEND: JVM
// SKIP_KT_DUMP
// FILE: kt44855.kt
open class Child(val x: Parent?) : Parent() {
inner class QQQ {
fun z() {
x as Child
val q = x.qqq
x.qqq = q + "OK"
}
}
}
// FILE: Parent.java
public class Parent {
protected String qqq = "";
public String getQqq() {
return qqq;
}
}
+79
View File
@@ -0,0 +1,79 @@
FILE fqName:<root> fileName:/kt44855.kt
CLASS CLASS name:Child modality:OPEN visibility:public superTypes:[<root>.Parent]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Child
CONSTRUCTOR visibility:public <> (x:<root>.Parent?) returnType:<root>.Child [primary]
VALUE_PARAMETER name:x index:0 type:<root>.Parent?
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Parent'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Child modality:OPEN visibility:public superTypes:[<root>.Parent]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:<root>.Parent? visibility:private [final]
EXPRESSION_BODY
GET_VAR 'x: <root>.Parent? declared in <root>.Child.<init>' type=<root>.Parent? origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:<root>.Child) returnType:<root>.Parent?
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Child
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-x> (): <root>.Parent? declared in <root>.Child'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:<root>.Parent? visibility:private [final]' type=<root>.Parent? origin=null
receiver: GET_VAR '<this>: <root>.Child declared in <root>.Child.<get-x>' type=<root>.Child origin=null
CLASS CLASS name:QQQ modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Child.QQQ
CONSTRUCTOR visibility:public <> ($this:<root>.Child) returnType:<root>.Child.QQQ [primary]
$outer: VALUE_PARAMETER name:<this> type:<root>.Child
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:QQQ modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]'
FUN name:z visibility:public modality:FINAL <> ($this:<root>.Child.QQQ) returnType:kotlin.Unit
$this: VALUE_PARAMETER name:<this> type:<root>.Child.QQQ
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
TYPE_OP type=<root>.Child origin=CAST typeOperand=<root>.Child
CALL 'public final fun <get-x> (): <root>.Parent? declared in <root>.Child' type=<root>.Parent? origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Child declared in <root>.Child' type=<root>.Child origin=null
VAR name:q type:@[FlexibleNullability] kotlin.String? [val]
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:qqq type:@[FlexibleNullability] kotlin.String? visibility:protected/*protected and package*/' type=@[FlexibleNullability] kotlin.String? origin=GET_PROPERTY
receiver: TYPE_OP type=<root>.Child origin=IMPLICIT_CAST typeOperand=<root>.Child
CALL 'public final fun <get-x> (): <root>.Parent? declared in <root>.Child' type=<root>.Parent? origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Child declared in <root>.Child' type=<root>.Child origin=null
SET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:qqq type:@[FlexibleNullability] kotlin.String? visibility:protected/*protected and package*/' type=kotlin.Unit origin=EQ
receiver: TYPE_OP type=<root>.Child origin=IMPLICIT_CAST typeOperand=<root>.Child
CALL 'public final fun <get-x> (): <root>.Parent? declared in <root>.Child' type=<root>.Parent? origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Child declared in <root>.Child' type=<root>.Child origin=null
value: CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=PLUS
$this: TYPE_OP type=kotlin.String origin=IMPLICIT_NOTNULL typeOperand=kotlin.String
GET_VAR 'val q: @[FlexibleNullability] kotlin.String? [val] declared in <root>.Child.QQQ.z' type=@[FlexibleNullability] kotlin.String? origin=null
other: CONST String type=kotlin.String value="OK"
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
PROPERTY FAKE_OVERRIDE name:qqq visibility:protected/*protected and package*/ modality:FINAL [fake_override,var]
overridden:
protected/*protected and package*/ final qqq: @[FlexibleNullability] kotlin.String? [var]
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.Parent
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:getQqq visibility:public modality:OPEN <> ($this:<root>.Parent) returnType:@[FlexibleNullability] kotlin.String? [fake_override]
overridden:
public open fun getQqq (): @[FlexibleNullability] kotlin.String? declared in <root>.Parent
$this: VALUE_PARAMETER name:<this> type:<root>.Parent
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int [fake_override] declared in <root>.Parent
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String [fake_override] declared in <root>.Parent
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -41319,6 +41319,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("kt44855.kt")
public void testKt44855() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt44855.kt");
}
@Test
@TestMetadata("kt44855a.kt")
public void testKt44855a() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt44855a.kt");
}
@Test
@TestMetadata("kt46578_anonObject.kt")
public void testKt46578_anonObject() throws Exception {
@@ -41421,6 +41421,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("kt44855.kt")
public void testKt44855() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt44855.kt");
}
@Test
@TestMetadata("kt44855a.kt")
public void testKt44855a() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt44855a.kt");
}
@Test
@TestMetadata("kt46578_anonObject.kt")
public void testKt46578_anonObject() throws Exception {
@@ -2484,6 +2484,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest {
runTest("compiler/testData/ir/irText/regressions/kt24114.kt");
}
@Test
@TestMetadata("kt44855.kt")
public void testKt44855() throws Exception {
runTest("compiler/testData/ir/irText/regressions/kt44855.kt");
}
@Test
@TestMetadata("kt45236.kt")
public void testKt45236() throws Exception {
@@ -33200,6 +33200,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ProtectedJavaFieldAccessor extends AbstractLightAnalysisModeTest {
@TestMetadata("kt44855.kt")
public void ignoreKt44855() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt44855.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -33208,6 +33213,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("kt44855a.kt")
public void testKt44855a() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt44855a.kt");
}
@TestMetadata("kt46578_anonObject.kt")
public void testKt46578_anonObject() throws Exception {
runTest("compiler/testData/codegen/box/syntheticAccessors/protectedJavaFieldAccessor/kt46578_anonObject.kt");