FIR2IR: change delegate field type to initializer type

This commit is contained in:
Mikhail Glukhikh
2021-12-03 14:11:40 +03:00
parent 49bb2a578e
commit a919351d07
10 changed files with 40 additions and 35 deletions
@@ -948,7 +948,11 @@ class Fir2IrDeclarationStorage(
fun getCachedIrField(field: FirField): IrField? = fieldCache[field]
fun createIrFieldAndDelegatedMembers(field: FirField, owner: FirClass, irClass: IrClass): IrField {
val irField = createIrField(field, origin = IrDeclarationOrigin.DELEGATE)
val irField = createIrField(
field,
typeRef = field.initializer?.typeRef ?: field.returnTypeRef,
origin = IrDeclarationOrigin.DELEGATE
)
irField.setAndModifyParent(irClass)
delegatedMemberGenerator.generate(irField, field, owner, irClass)
if (owner.isLocalClassOrAnonymousObject()) {
@@ -959,9 +963,10 @@ class Fir2IrDeclarationStorage(
private fun createIrField(
field: FirField,
typeRef: FirTypeRef = field.returnTypeRef,
origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
): IrField = convertCatching(field) {
val type = field.returnTypeRef.toIrType()
val type = typeRef.toIrType()
return field.convertWithOffsets { startOffset, endOffset ->
irFactory.createField(
startOffset, endOffset, origin, IrFieldSymbolImpl(),
@@ -216,7 +216,7 @@ FILE fqName:<root> fileName:/delegatedImplementation.kt
VALUE_PARAMETER name:s index:1 type:kotlin.String
BLOCK_BODY
CALL 'public abstract fun foo (x: kotlin.Int, s: kotlin.String): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase visibility:local [final]' type=<root>.IBase origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.BaseImpl visibility:local [final]' type=<root>.BaseImpl origin=null
receiver: GET_VAR '<this>: <root>.Test1 declared in <root>.Test1.foo' type=<root>.Test1 origin=null
x: GET_VAR 'x: kotlin.Int declared in <root>.Test1.foo' type=kotlin.Int origin=null
s: GET_VAR 's: kotlin.String declared in <root>.Test1.foo' type=kotlin.String origin=null
@@ -227,7 +227,7 @@ FILE fqName:<root> fileName:/delegatedImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun bar (): kotlin.Int declared in <root>.Test1'
CALL 'public abstract fun bar (): kotlin.Int declared in <root>.IBase' type=kotlin.Int origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase visibility:local [final]' type=<root>.IBase origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.BaseImpl visibility:local [final]' type=<root>.BaseImpl origin=null
receiver: GET_VAR '<this>: <root>.Test1 declared in <root>.Test1.bar' type=<root>.Test1 origin=null
FUN DELEGATED_MEMBER name:qux visibility:public modality:OPEN <> ($this:<root>.Test1, $receiver:kotlin.String) returnType:kotlin.Unit
overridden:
@@ -236,10 +236,10 @@ FILE fqName:<root> fileName:/delegatedImplementation.kt
$receiver: VALUE_PARAMETER name:<this> type:kotlin.String
BLOCK_BODY
CALL 'public abstract fun qux (): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase visibility:local [final]' type=<root>.IBase origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.BaseImpl visibility:local [final]' type=<root>.BaseImpl origin=null
receiver: GET_VAR '<this>: <root>.Test1 declared in <root>.Test1.qux' type=<root>.Test1 origin=null
$receiver: GET_VAR '<this>: kotlin.String declared in <root>.Test1.qux' type=kotlin.String origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.BaseImpl visibility:local [final]
EXPRESSION_BODY
GET_OBJECT 'CLASS OBJECT name:BaseImpl modality:FINAL visibility:public superTypes:[<root>.IBase]' type=<root>.BaseImpl
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -269,7 +269,7 @@ FILE fqName:<root> fileName:/delegatedImplementation.kt
VALUE_PARAMETER name:s index:1 type:kotlin.String
BLOCK_BODY
CALL 'public abstract fun foo (x: kotlin.Int, s: kotlin.String): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase visibility:local [final]' type=<root>.IBase origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.BaseImpl visibility:local [final]' type=<root>.BaseImpl origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.foo' type=<root>.Test2 origin=null
x: GET_VAR 'x: kotlin.Int declared in <root>.Test2.foo' type=kotlin.Int origin=null
s: GET_VAR 's: kotlin.String declared in <root>.Test2.foo' type=kotlin.String origin=null
@@ -280,7 +280,7 @@ FILE fqName:<root> fileName:/delegatedImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun bar (): kotlin.Int declared in <root>.Test2'
CALL 'public abstract fun bar (): kotlin.Int declared in <root>.IBase' type=kotlin.Int origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase visibility:local [final]' type=<root>.IBase origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.BaseImpl visibility:local [final]' type=<root>.BaseImpl origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.bar' type=<root>.Test2 origin=null
FUN DELEGATED_MEMBER name:qux visibility:public modality:OPEN <> ($this:<root>.Test2, $receiver:kotlin.String) returnType:kotlin.Unit
overridden:
@@ -289,10 +289,10 @@ FILE fqName:<root> fileName:/delegatedImplementation.kt
$receiver: VALUE_PARAMETER name:<this> type:kotlin.String
BLOCK_BODY
CALL 'public abstract fun qux (): kotlin.Unit declared in <root>.IBase' type=kotlin.Unit origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase visibility:local [final]' type=<root>.IBase origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.BaseImpl visibility:local [final]' type=<root>.BaseImpl origin=null
receiver: GET_VAR '<this>: <root>.Test2 declared in <root>.Test2.qux' type=<root>.Test2 origin=null
$receiver: GET_VAR '<this>: kotlin.String declared in <root>.Test2.qux' type=kotlin.String origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IBase visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.BaseImpl visibility:local [final]
EXPRESSION_BODY
GET_OBJECT 'CLASS OBJECT name:BaseImpl modality:FINAL visibility:public superTypes:[<root>.IBase]' type=<root>.BaseImpl
PROPERTY DELEGATED_MEMBER name:x visibility:public modality:OPEN [val]
@@ -96,7 +96,7 @@ class Test1 : IBase {
(<this>.#<$$delegate_0>, <this>).qux()
}
local /* final field */ val <$$delegate_0>: IBase = BaseImpl
local /* final field */ val <$$delegate_0>: BaseImpl = BaseImpl
}
@@ -119,7 +119,7 @@ class Test2 : IBase, IOther {
(<this>.#<$$delegate_0>, <this>).qux()
}
local /* final field */ val <$$delegate_0>: IBase = BaseImpl
local /* final field */ val <$$delegate_0>: BaseImpl = BaseImpl
override val x: String
override get(): String {
return <this>.#<$$delegate_1>.<get-x>()
@@ -59,9 +59,9 @@ FILE fqName:<root> fileName:/delegatedImplementationWithExplicitOverride.kt
$this: VALUE_PARAMETER name:<this> type:<root>.C
BLOCK_BODY
CALL 'public abstract fun foo (): kotlin.Unit declared in <root>.IFooBar' type=kotlin.Unit origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFooBar visibility:local [final]' type=<root>.IFooBar origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.FooBarImpl visibility:local [final]' type=<root>.FooBarImpl origin=null
receiver: GET_VAR '<this>: <root>.C declared in <root>.C.foo' type=<root>.C origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IFooBar visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.FooBarImpl visibility:local [final]
EXPRESSION_BODY
GET_OBJECT 'CLASS OBJECT name:FooBarImpl modality:FINAL visibility:public superTypes:[<root>.IFooBar]' type=<root>.FooBarImpl
FUN name:bar visibility:public modality:FINAL <> ($this:<root>.C) returnType:kotlin.Unit
@@ -30,7 +30,7 @@ class C : IFooBar {
<this>.#<$$delegate_0>.foo()
}
local /* final field */ val <$$delegate_0>: IFooBar = FooBarImpl
local /* final field */ val <$$delegate_0>: FooBarImpl = FooBarImpl
override fun bar() {
}
@@ -138,9 +138,9 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun foo (): kotlin.String declared in <root>.TestJFoo'
CALL 'public abstract fun foo (): kotlin.String declared in <root>.IFoo' type=kotlin.String origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.JFoo visibility:local [final]' type=<root>.JFoo origin=null
receiver: GET_VAR '<this>: <root>.TestJFoo declared in <root>.TestJFoo.foo' type=<root>.TestJFoo origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.JFoo visibility:local [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.JFoo' type=<root>.JFoo origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -169,9 +169,9 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun foo (): kotlin.String declared in <root>.TestK1'
CALL 'public abstract fun foo (): kotlin.String declared in <root>.IFoo' type=kotlin.String origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.K1 visibility:local [final]' type=<root>.K1 origin=null
receiver: GET_VAR '<this>: <root>.TestK1 declared in <root>.TestK1.foo' type=<root>.TestK1 origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.K1 visibility:local [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K1' type=<root>.K1 origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -200,9 +200,9 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun foo (): kotlin.String declared in <root>.TestK2'
CALL 'public abstract fun foo (): kotlin.String declared in <root>.IFoo' type=kotlin.String origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.K2 visibility:local [final]' type=<root>.K2 origin=null
receiver: GET_VAR '<this>: <root>.TestK2 declared in <root>.TestK2.foo' type=<root>.TestK2 origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.K2 visibility:local [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K2' type=<root>.K2 origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -231,9 +231,9 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun foo (): kotlin.String declared in <root>.TestK3'
CALL 'public abstract fun foo (): kotlin.String declared in <root>.IFoo' type=kotlin.String origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.K3 visibility:local [final]' type=<root>.K3 origin=null
receiver: GET_VAR '<this>: <root>.TestK3 declared in <root>.TestK3.foo' type=<root>.TestK3 origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.K3 visibility:local [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K3' type=<root>.K3 origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -262,9 +262,9 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun foo (): kotlin.String declared in <root>.TestK4'
CALL 'public abstract fun foo (): kotlin.String declared in <root>.IFoo' type=kotlin.String origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.K4 visibility:local [final]' type=<root>.K4 origin=null
receiver: GET_VAR '<this>: <root>.TestK4 declared in <root>.TestK4.foo' type=<root>.TestK4 origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.K4 visibility:local [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K4' type=<root>.K4 origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -58,7 +58,7 @@ class TestJFoo : IFoo {
return <this>.#<$$delegate_0>.foo()
}
local /* final field */ val <$$delegate_0>: IFoo = JFoo()
local /* final field */ val <$$delegate_0>: JFoo = JFoo()
}
@@ -73,7 +73,7 @@ class TestK1 : IFoo {
return <this>.#<$$delegate_0>.foo()
}
local /* final field */ val <$$delegate_0>: IFoo = K1()
local /* final field */ val <$$delegate_0>: K1 = K1()
}
@@ -88,7 +88,7 @@ class TestK2 : IFoo {
return <this>.#<$$delegate_0>.foo()
}
local /* final field */ val <$$delegate_0>: IFoo = K2()
local /* final field */ val <$$delegate_0>: K2 = K2()
}
@@ -103,7 +103,7 @@ class TestK3 : IFoo {
return <this>.#<$$delegate_0>.foo()
}
local /* final field */ val <$$delegate_0>: IFoo = K3()
local /* final field */ val <$$delegate_0>: K3 = K3()
}
@@ -118,6 +118,6 @@ class TestK4 : IFoo {
return <this>.#<$$delegate_0>.foo()
}
local /* final field */ val <$$delegate_0>: IFoo = K4()
local /* final field */ val <$$delegate_0>: K4 = K4()
}
+2 -2
View File
@@ -15,9 +15,9 @@ FILE fqName:<root> fileName:/kt45934.kt
RETURN type=kotlin.Nothing from='public open fun foo <C> (): @[FlexibleNullability] kotlin.collections.List<@[FlexibleNullability] C of <root>.C.foo?>? declared in <root>.C'
CALL 'public abstract fun foo <C> (): @[FlexibleNullability] kotlin.collections.List<@[FlexibleNullability] C of <root>.I.foo?>? declared in <root>.I' type=@[FlexibleNullability] kotlin.collections.List<@[FlexibleNullability] C of <root>.C.foo?>? origin=null
<C>: C of <root>.C.foo
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.I visibility:local [final]' type=<root>.I origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.J visibility:local [final]' type=<root>.J origin=null
receiver: GET_VAR '<this>: <root>.C declared in <root>.C.foo' type=<root>.C origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.I visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.J visibility:local [final]
EXPRESSION_BODY
GET_VAR 'client: <root>.J declared in <root>.C.<init>' type=<root>.J origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -62,9 +62,9 @@ FILE fqName:<root> fileName:/nullCheckOnInterfaceDelegation.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun foo (): kotlin.String declared in <root>.Delegated'
CALL 'public abstract fun foo (): kotlin.String declared in <root>.IFoo' type=kotlin.String origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]' type=<root>.IFoo origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.Derived visibility:local [final]' type=<root>.Derived origin=null
receiver: GET_VAR '<this>: <root>.Delegated declared in <root>.Delegated.foo' type=<root>.Delegated origin=null
FIELD DELEGATE name:<$$delegate_0> type:<root>.IFoo visibility:local [final]
FIELD DELEGATE name:<$$delegate_0> type:<root>.Derived visibility:local [final]
EXPRESSION_BODY
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.Derived' type=<root>.Derived origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -31,7 +31,7 @@ class Delegated : IFoo {
return <this>.#<$$delegate_0>.foo()
}
local /* final field */ val <$$delegate_0>: IFoo = Derived()
local /* final field */ val <$$delegate_0>: Derived = Derived()
}