[FIR2IR] Create delegated field for delegation to var property

^KT-65920 Fixed
This commit is contained in:
Dmitriy Novozhilov
2024-02-19 14:57:08 +02:00
committed by Space Team
parent 26fae9e83a
commit 3469e3b198
24 changed files with 152 additions and 9 deletions
@@ -16862,6 +16862,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -16862,6 +16862,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -583,7 +583,7 @@ class Fir2IrConverter(
requireNotNull(delegateFieldToPropertyMap)
require(parent is IrClass)
val correspondingClassProperty = declaration.findCorrespondingDelegateProperty(containingClass)
if (correspondingClassProperty == null) {
if (correspondingClassProperty == null || correspondingClassProperty.isVar) {
val irField = declarationStorage.createDelegateIrField(declaration, parent)
delegatedMemberGenerator.generateWithBodiesIfNeeded(declaration, irField, containingClass, parent)
} else {
@@ -16803,6 +16803,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -16803,6 +16803,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -16803,6 +16803,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -0,0 +1,20 @@
// ISSUE: KT-65920
interface I {
fun foo()
}
class Test2(var j: I) : I by j
fun box(): String {
var result = ""
val x = Test2(object : I { override fun foo() { result += "1" }})
x.foo()
x.j = object : I { override fun foo() { result += "2" }}
x.foo()
return when (result) {
"11" -> "OK"
else -> "Fail: $result"
}
}
@@ -88,6 +88,9 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
<set-?>: GET_VAR '<set-?>: D of <root>.Test1.<set-x>? declared in <root>.Test1.<set-x>' type=D of <root>.Test1.<set-x>? origin=null
CLASS CLASS name:Test2 modality:FINAL visibility:public superTypes:[<root>.IBase<kotlin.String>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test2
FIELD DELEGATE name:$$delegate_0 type:<root>.IBase<kotlin.String> visibility:private [final]
EXPRESSION_BODY
GET_VAR 'j: <root>.IBase<kotlin.String> declared in <root>.Test2.<init>' type=<root>.IBase<kotlin.String> origin=null
PROPERTY name:j visibility:public modality:FINAL [var]
FIELD PROPERTY_BACKING_FIELD name:j type:<root>.IBase<kotlin.String> visibility:private
EXPRESSION_BODY
@@ -122,7 +125,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
BLOCK_BODY
CALL 'public abstract fun foo <B> (a: A of <root>.IBase, b: B of <root>.IBase.foo): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
<B>: B of <root>.Test2.foo
$this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j type:<root>.IBase<kotlin.String> visibility:private' type=<root>.IBase<kotlin.String> origin=null
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IBase<kotlin.String> visibility:private [final]' type=<root>.IBase<kotlin.String> origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.foo' type=<root>.Test2 origin=null
a: GET_VAR 'a: kotlin.String declared in <root>.Test2.foo' type=kotlin.String origin=null
b: GET_VAR 'b: B of <root>.Test2.foo declared in <root>.Test2.foo' type=B of <root>.Test2.foo origin=null
@@ -153,7 +156,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
RETURN type=kotlin.Nothing from='public open fun <get-id> <C> (): kotlin.collections.Map<kotlin.String, C of <root>.Test2.<get-id>>? declared in <root>.Test2'
CALL 'public abstract fun <get-id> <C> (): kotlin.collections.Map<A of <root>.IBase, C of <root>.IBase.<get-id>>? declared in <root>.IBase' type=kotlin.collections.Map<kotlin.String, C of <root>.Test2.<get-id>>? origin=null
<C>: C of <root>.Test2.<get-id>
$this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j type:<root>.IBase<kotlin.String> visibility:private' type=<root>.IBase<kotlin.String> origin=null
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IBase<kotlin.String> visibility:private [final]' type=<root>.IBase<kotlin.String> origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.<get-id>' type=<root>.Test2 origin=null
$receiver: GET_VAR '<this>: C of <root>.Test2.<get-id> declared in <root>.Test2.<get-id>' type=C of <root>.Test2.<get-id> origin=null
PROPERTY DELEGATED_MEMBER name:x visibility:public modality:OPEN [var]
@@ -170,7 +173,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
RETURN type=kotlin.Nothing from='public open fun <get-x> <D> (): D of <root>.Test2.<get-x>? declared in <root>.Test2'
CALL 'public abstract fun <get-x> <D> (): D of <root>.IBase.<get-x>? declared in <root>.IBase' type=D of <root>.Test2.<get-x>? origin=null
<D>: D of <root>.Test2.<get-x>
$this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j type:<root>.IBase<kotlin.String> visibility:private' type=<root>.IBase<kotlin.String> origin=null
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IBase<kotlin.String> visibility:private [final]' type=<root>.IBase<kotlin.String> origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.<get-x>' type=<root>.Test2 origin=null
$receiver: GET_VAR '<this>: kotlin.collections.List<D of <root>.Test2.<get-x>> declared in <root>.Test2.<get-x>' type=kotlin.collections.List<D of <root>.Test2.<get-x>> origin=null
FUN DELEGATED_MEMBER name:<set-x> visibility:public modality:OPEN <D> ($this:<root>.Test2, $receiver:kotlin.collections.List<D of <root>.Test2.<set-x>>, <set-?>:D of <root>.Test2.<set-x>?) returnType:kotlin.Unit
@@ -184,7 +187,7 @@ FILE fqName:<root> fileName:/delegatedGenericImplementation.kt
BLOCK_BODY
CALL 'public abstract fun <set-x> <D> (<set-?>: D of <root>.IBase.<set-x>?): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
<D>: D of <root>.Test2.<set-x>
$this: GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j type:<root>.IBase<kotlin.String> visibility:private' type=<root>.IBase<kotlin.String> origin=null
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IBase<kotlin.String> visibility:private [final]' type=<root>.IBase<kotlin.String> origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.<set-x>' type=<root>.Test2 origin=null
$receiver: GET_VAR '<this>: kotlin.collections.List<D of <root>.Test2.<set-x>> declared in <root>.Test2.<set-x>' type=kotlin.collections.List<D of <root>.Test2.<set-x>> origin=null
<set-?>: GET_VAR '<set-?>: D of <root>.Test2.<set-x>? declared in <root>.Test2.<set-x>' type=D of <root>.Test2.<set-x>? origin=null
@@ -26,6 +26,7 @@ class Test1<E : Any?> : IBase<E> {
}
class Test2 : IBase<String> {
private /* final field */ val $$delegate_0: IBase<String> = j
var j: IBase<String>
field = j
get
@@ -38,20 +39,20 @@ class Test2 : IBase<String> {
}
override fun <B : Any?> foo(a: String, b: B) {
<this>.#j.foo<B>(a = a, b = b)
<this>.#$$delegate_0.foo<B>(a = a, b = b)
}
override val <C : Any?> C.id: Map<String, C>?
override get(): Map<String, C>? {
return (<this>.#j, <this>).<get-id><C>()
return (<this>.#$$delegate_0, <this>).<get-id><C>()
}
override var <D : Any?> List<D>.x: D?
override get(): D? {
return (<this>.#j, <this>).<get-x><D>()
return (<this>.#$$delegate_0, <this>).<get-x><D>()
}
override set(<set-?>: D?) {
(<this>.#j, <this>).<set-x><D>(<set-?> = <set-?>)
(<this>.#$$delegate_0, <this>).<set-x><D>(<set-?> = <set-?>)
}
}
@@ -16803,6 +16803,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -16419,6 +16419,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -16803,6 +16803,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -16803,6 +16803,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -13864,6 +13864,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/delegation/delegationToVal.kt");
}
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
runTest("compiler/testData/codegen/box/delegation/delegationWithPrivateConstructor.kt");
@@ -12753,6 +12753,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -12753,6 +12753,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -12753,6 +12753,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -12753,6 +12753,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -13808,6 +13808,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -14122,6 +14122,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -13494,6 +13494,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -13809,6 +13809,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -12729,6 +12729,12 @@ public class FirWasmJsCodegenBoxTestGenerated extends AbstractFirWasmJsCodegenBo
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {
@@ -12729,6 +12729,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest
runTest("compiler/testData/codegen/box/delegation/delegationToIntersectionType.kt");
}
@Test
@TestMetadata("delegationToVar.kt")
public void testDelegationToVar() {
runTest("compiler/testData/codegen/box/delegation/delegationToVar.kt");
}
@Test
@TestMetadata("delegationWithPrivateConstructor.kt")
public void testDelegationWithPrivateConstructor() {