[FIR] add support for implementation by delgation
This commit handles "subclass: super-interface by delegate-expression". During Psi2Fir, for each delegate, we add to the subclass a synthetic field (which has type super-interface), and an assignment of the delegate-expression to the synthetic field in the primary constructor, so that the delegate-expression can be resolved and transformed along the way. During Fir2Ir, we look up delegatable members from the super-interface and generate corresponding functions/properties for the subclass. TODO: support for generic delegatable members and generic super-interface.
This commit is contained in:
committed by
Mikhail Glukhikh
parent
1d45dc8d81
commit
d163853c97
+55
-10
@@ -123,10 +123,19 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:TestJFoo modality:FINAL visibility:public superTypes:[<root>.IFoo]'
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.IFoo) returnType:kotlin.String [fake_override]
|
||||
SET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IFoo visibility:local [final]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.TestJFoo declared in <root>.TestJFoo' type=<root>.TestJFoo origin=null
|
||||
value: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.JFoo' type=<root>.JFoo origin=null
|
||||
FUN DELEGATED_MEMBER name:foo visibility:public modality:OPEN <> ($this:<root>.TestJFoo) returnType:kotlin.String
|
||||
overridden:
|
||||
public abstract fun foo (): kotlin.String declared in <root>.IFoo
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.IFoo
|
||||
$this: VALUE_PARAMETER DELEGATED_MEMBER name:<this> type:<root>.TestJFoo
|
||||
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
|
||||
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]
|
||||
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
|
||||
@@ -146,10 +155,19 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:TestK1 modality:FINAL visibility:public superTypes:[<root>.IFoo]'
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.IFoo) returnType:kotlin.String [fake_override]
|
||||
SET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IFoo visibility:local [final]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.TestK1 declared in <root>.TestK1' type=<root>.TestK1 origin=null
|
||||
value: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K1' type=<root>.K1 origin=null
|
||||
FUN DELEGATED_MEMBER name:foo visibility:public modality:OPEN <> ($this:<root>.TestK1) returnType:kotlin.String
|
||||
overridden:
|
||||
public abstract fun foo (): kotlin.String declared in <root>.IFoo
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.IFoo
|
||||
$this: VALUE_PARAMETER DELEGATED_MEMBER name:<this> type:<root>.TestK1
|
||||
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
|
||||
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]
|
||||
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
|
||||
@@ -169,10 +187,19 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:TestK2 modality:FINAL visibility:public superTypes:[<root>.IFoo]'
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.IFoo) returnType:kotlin.String [fake_override]
|
||||
SET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IFoo visibility:local [final]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.TestK2 declared in <root>.TestK2' type=<root>.TestK2 origin=null
|
||||
value: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K2' type=<root>.K2 origin=null
|
||||
FUN DELEGATED_MEMBER name:foo visibility:public modality:OPEN <> ($this:<root>.TestK2) returnType:kotlin.String
|
||||
overridden:
|
||||
public abstract fun foo (): kotlin.String declared in <root>.IFoo
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.IFoo
|
||||
$this: VALUE_PARAMETER DELEGATED_MEMBER name:<this> type:<root>.TestK2
|
||||
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
|
||||
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]
|
||||
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
|
||||
@@ -192,10 +219,19 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:TestK3 modality:FINAL visibility:public superTypes:[<root>.IFoo]'
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.IFoo) returnType:kotlin.String [fake_override]
|
||||
SET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IFoo visibility:local [final]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.TestK3 declared in <root>.TestK3' type=<root>.TestK3 origin=null
|
||||
value: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K3' type=<root>.K3 origin=null
|
||||
FUN DELEGATED_MEMBER name:foo visibility:public modality:OPEN <> ($this:<root>.TestK3) returnType:kotlin.String
|
||||
overridden:
|
||||
public abstract fun foo (): kotlin.String declared in <root>.IFoo
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.IFoo
|
||||
$this: VALUE_PARAMETER DELEGATED_MEMBER name:<this> type:<root>.TestK3
|
||||
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
|
||||
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]
|
||||
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
|
||||
@@ -215,10 +251,19 @@ FILE fqName:<root> fileName:/implicitNotNullOnDelegatedImplementation.kt
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:TestK4 modality:FINAL visibility:public superTypes:[<root>.IFoo]'
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:<root>.IFoo) returnType:kotlin.String [fake_override]
|
||||
SET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.IFoo visibility:local [final]' type=kotlin.Unit origin=EQ
|
||||
receiver: GET_VAR '<this>: <root>.TestK4 declared in <root>.TestK4' type=<root>.TestK4 origin=null
|
||||
value: CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in <root>.K4' type=<root>.K4 origin=null
|
||||
FUN DELEGATED_MEMBER name:foo visibility:public modality:OPEN <> ($this:<root>.TestK4) returnType:kotlin.String
|
||||
overridden:
|
||||
public abstract fun foo (): kotlin.String declared in <root>.IFoo
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.IFoo
|
||||
$this: VALUE_PARAMETER DELEGATED_MEMBER name:<this> type:<root>.TestK4
|
||||
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
|
||||
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]
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user