diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt index 4c8e8ccd3ba..8d40975a121 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt @@ -10,10 +10,8 @@ import org.jetbrains.kotlin.backend.common.ir.isOverridable import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities as OldVisibilities import org.jetbrains.kotlin.fir.Visibilities -import org.jetbrains.kotlin.fir.backend.Fir2IrComponents -import org.jetbrains.kotlin.fir.backend.FirMetadataSource +import org.jetbrains.kotlin.fir.backend.* import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter -import org.jetbrains.kotlin.fir.backend.isOverriding import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.builder.buildProperty import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction @@ -233,6 +231,10 @@ internal class DelegatedMemberGenerator( } irTypeSubstitutor = IrTypeSubstitutor(substParameters, substArguments, irBuiltIns) } + superFunction.extensionReceiverParameter?.let { + val substitutedType = if (addTypeSubstitution) irTypeSubstitutor.substitute(it.type) else it.type + extensionReceiverParameter = declareThisReceiverParameter(symbolTable, substitutedType, origin) + } valueParameters = superFunction.valueParameters.map { valueParameter -> val parameterDescriptor = WrappedValueParameterDescriptor() val substedType = if (addTypeSubstitution) irTypeSubstitutor.substitute(valueParameter.type) else valueParameter.type diff --git a/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberExtValDelegationWithInlineClassParameterTypes.kt b/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberExtValDelegationWithInlineClassParameterTypes.kt index f7d09410c3b..c522ffff3c2 100644 --- a/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberExtValDelegationWithInlineClassParameterTypes.kt +++ b/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberExtValDelegationWithInlineClassParameterTypes.kt @@ -1,6 +1,5 @@ // KJS_WITH_FULL_RUNTIME // WITH_RUNTIME -// IGNORE_BACKEND_FIR: JVM_IR import kotlin.test.assertEquals inline class S(val x: String) diff --git a/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberExtVarDelegationWithInlineClassParameterTypes.kt b/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberExtVarDelegationWithInlineClassParameterTypes.kt index e637e022329..7808a26a6ab 100644 --- a/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberExtVarDelegationWithInlineClassParameterTypes.kt +++ b/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberExtVarDelegationWithInlineClassParameterTypes.kt @@ -1,6 +1,5 @@ // KJS_WITH_FULL_RUNTIME // WITH_RUNTIME -// IGNORE_BACKEND_FIR: JVM_IR import kotlin.test.assertEquals diff --git a/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberFunDelegationToInlineClassWithInlineClassParameterTypes.kt b/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberFunDelegationToInlineClassWithInlineClassParameterTypes.kt index 648f32a4ddd..7f9223bec32 100644 --- a/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberFunDelegationToInlineClassWithInlineClassParameterTypes.kt +++ b/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberFunDelegationToInlineClassWithInlineClassParameterTypes.kt @@ -1,6 +1,5 @@ // KJS_WITH_FULL_RUNTIME // WITH_RUNTIME -// IGNORE_BACKEND_FIR: JVM_IR import kotlin.test.assertEquals inline class S(val x: String) diff --git a/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberFunDelegationWithInlineClassParameterTypes.kt b/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberFunDelegationWithInlineClassParameterTypes.kt index b95884783ae..69522dcf2b9 100644 --- a/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberFunDelegationWithInlineClassParameterTypes.kt +++ b/compiler/testData/codegen/box/inlineClasses/interfaceDelegation/memberFunDelegationWithInlineClassParameterTypes.kt @@ -1,6 +1,5 @@ // KJS_WITH_FULL_RUNTIME // WITH_RUNTIME -// IGNORE_BACKEND_FIR: JVM_IR import kotlin.test.assertEquals inline class S(val x: String) diff --git a/compiler/testData/ir/irText/classes/delegatedImplementation.fir.txt b/compiler/testData/ir/irText/classes/delegatedImplementation.fir.txt index 2a87a8673c5..115b7bd8904 100644 --- a/compiler/testData/ir/irText/classes/delegatedImplementation.fir.txt +++ b/compiler/testData/ir/irText/classes/delegatedImplementation.fir.txt @@ -224,14 +224,16 @@ FILE fqName: fileName:/delegatedImplementation.kt CALL 'public abstract fun bar (): kotlin.Int declared in .IBase' type=kotlin.Int origin=null $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.IBase visibility:local [final]' type=.IBase origin=null receiver: GET_VAR ': .Test1 declared in .Test1.bar' type=.Test1 origin=null - FUN DELEGATED_MEMBER name:qux visibility:public modality:OPEN <> ($this:.Test1) returnType:kotlin.Unit + FUN DELEGATED_MEMBER name:qux visibility:public modality:OPEN <> ($this:.Test1, $receiver:kotlin.String) returnType:kotlin.Unit overridden: public abstract fun qux (): kotlin.Unit declared in .IBase $this: VALUE_PARAMETER DELEGATED_MEMBER name: type:.Test1 + $receiver: VALUE_PARAMETER DELEGATED_MEMBER name: type:kotlin.String BLOCK_BODY CALL 'public abstract fun qux (): kotlin.Unit declared in .IBase' type=kotlin.Unit origin=null $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.IBase visibility:local [final]' type=.IBase origin=null receiver: GET_VAR ': .Test1 declared in .Test1.qux' type=.Test1 origin=null + $receiver: GET_VAR ': kotlin.String declared in .Test1.qux' type=kotlin.String origin=null FIELD DELEGATE name:<$$delegate_0> type:.IBase 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: @@ -281,14 +283,16 @@ FILE fqName: fileName:/delegatedImplementation.kt CALL 'public abstract fun bar (): kotlin.Int declared in .IBase' type=kotlin.Int origin=null $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.IBase visibility:local [final]' type=.IBase origin=null receiver: GET_VAR ': .Test2 declared in .Test2.bar' type=.Test2 origin=null - FUN DELEGATED_MEMBER name:qux visibility:public modality:OPEN <> ($this:.Test2) returnType:kotlin.Unit + FUN DELEGATED_MEMBER name:qux visibility:public modality:OPEN <> ($this:.Test2, $receiver:kotlin.String) returnType:kotlin.Unit overridden: public abstract fun qux (): kotlin.Unit declared in .IBase $this: VALUE_PARAMETER DELEGATED_MEMBER name: type:.Test2 + $receiver: VALUE_PARAMETER DELEGATED_MEMBER name: type:kotlin.String BLOCK_BODY CALL 'public abstract fun qux (): kotlin.Unit declared in .IBase' type=kotlin.Unit origin=null $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.IBase visibility:local [final]' type=.IBase origin=null receiver: GET_VAR ': .Test2 declared in .Test2.qux' type=.Test2 origin=null + $receiver: GET_VAR ': kotlin.String declared in .Test2.qux' type=kotlin.String origin=null FIELD DELEGATE name:<$$delegate_0> type:.IBase visibility:local [final] PROPERTY DELEGATED_MEMBER name:x visibility:public modality:OPEN [val] FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Test2) returnType:kotlin.String @@ -324,37 +328,43 @@ FILE fqName: fileName:/delegatedImplementation.kt receiver: GET_VAR ': .Test2 declared in .Test2.' type=.Test2 origin=null : GET_VAR ': kotlin.Int declared in .Test2.' type=kotlin.Int origin=null PROPERTY DELEGATED_MEMBER name:z1 visibility:public modality:OPEN [val] - FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Test2) returnType:kotlin.Int + FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Test2, $receiver:kotlin.Byte) returnType:kotlin.Int correspondingProperty: PROPERTY DELEGATED_MEMBER name:z1 visibility:public modality:OPEN [val] overridden: public abstract fun (): kotlin.Int declared in .IOther $this: VALUE_PARAMETER DELEGATED_MEMBER name: type:.Test2 + $receiver: VALUE_PARAMETER DELEGATED_MEMBER name: type:kotlin.Byte BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun (): kotlin.Int declared in .Test2' CALL 'public abstract fun (): kotlin.Int declared in .IOther' type=kotlin.Int origin=null $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_1> type:.IOther visibility:local [final]' type=.IOther origin=null receiver: GET_VAR ': .Test2 declared in .Test2.' type=.Test2 origin=null + $receiver: GET_VAR ': kotlin.Byte declared in .Test2.' type=kotlin.Byte origin=null PROPERTY DELEGATED_MEMBER name:z2 visibility:public modality:OPEN [var] - FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Test2) returnType:kotlin.Int + FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Test2, $receiver:kotlin.Byte) returnType:kotlin.Int correspondingProperty: PROPERTY DELEGATED_MEMBER name:z2 visibility:public modality:OPEN [var] overridden: public abstract fun (): kotlin.Int declared in .IOther $this: VALUE_PARAMETER DELEGATED_MEMBER name: type:.Test2 + $receiver: VALUE_PARAMETER DELEGATED_MEMBER name: type:kotlin.Byte BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun (): kotlin.Int declared in .Test2' CALL 'public abstract fun (): kotlin.Int declared in .IOther' type=kotlin.Int origin=null $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_1> type:.IOther visibility:local [final]' type=.IOther origin=null receiver: GET_VAR ': .Test2 declared in .Test2.' type=.Test2 origin=null - FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Test2, :kotlin.Int) returnType:kotlin.Unit + $receiver: GET_VAR ': kotlin.Byte declared in .Test2.' type=kotlin.Byte origin=null + FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Test2, $receiver:kotlin.Byte, :kotlin.Int) returnType:kotlin.Unit correspondingProperty: PROPERTY DELEGATED_MEMBER name:z2 visibility:public modality:OPEN [var] overridden: public abstract fun (: kotlin.Int): kotlin.Unit declared in .IOther $this: VALUE_PARAMETER DELEGATED_MEMBER name: type:.Test2 + $receiver: VALUE_PARAMETER DELEGATED_MEMBER name: type:kotlin.Byte VALUE_PARAMETER DELEGATED_MEMBER name: index:0 type:kotlin.Int BLOCK_BODY CALL 'public abstract fun (: kotlin.Int): kotlin.Unit declared in .IOther' type=kotlin.Unit origin=null $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_1> type:.IOther visibility:local [final]' type=.IOther origin=null receiver: GET_VAR ': .Test2 declared in .Test2.' type=.Test2 origin=null + $receiver: GET_VAR ': kotlin.Byte declared in .Test2.' type=kotlin.Byte origin=null : GET_VAR ': kotlin.Int declared in .Test2.' type=kotlin.Int origin=null FIELD DELEGATE name:<$$delegate_1> type:.IOther visibility:local [final] FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] diff --git a/compiler/testData/ir/irText/declarations/kt35550.fir.txt b/compiler/testData/ir/irText/declarations/kt35550.fir.txt index 26a573ae014..2a5e7545ff5 100644 --- a/compiler/testData/ir/irText/declarations/kt35550.fir.txt +++ b/compiler/testData/ir/irText/declarations/kt35550.fir.txt @@ -34,18 +34,20 @@ FILE fqName: fileName:/kt35550.kt receiver: GET_VAR ': .A declared in .A' type=.A origin=null value: GET_VAR 'i: .I declared in .A.' type=.I origin=null PROPERTY DELEGATED_MEMBER name:id visibility:public modality:OPEN [val] - FUN DELEGATED_MEMBER name: visibility:public modality:OPEN ($this:.A) returnType:T of .I. + FUN DELEGATED_MEMBER name: visibility:public modality:OPEN ($this:.A, $receiver:T of .A.) returnType:T of .I. correspondingProperty: PROPERTY DELEGATED_MEMBER name:id visibility:public modality:OPEN [val] overridden: public open fun (): T of .I. declared in .I - TYPE_PARAMETER DELEGATED_MEMBER name:T index:0 variance: superTypes:[] + TYPE_PARAMETER DELEGATED_MEMBER name:T index:0 variance: superTypes:[kotlin.Any?] $this: VALUE_PARAMETER DELEGATED_MEMBER name: type:.A + $receiver: VALUE_PARAMETER DELEGATED_MEMBER name: type:T of .A. BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun (): T of .I. declared in .A' CALL 'public open fun (): T of .I. declared in .I' type=T of .A. origin=null : $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.I visibility:local [final]' type=.I origin=null receiver: GET_VAR ': .A declared in .A.' type=.A origin=null + $receiver: GET_VAR ': T of .A. declared in .A.' type=T of .A. origin=null FIELD DELEGATE name:<$$delegate_0> type:.I 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: diff --git a/compiler/testData/ir/irText/declarations/parameters/delegatedMembers.fir.txt b/compiler/testData/ir/irText/declarations/parameters/delegatedMembers.fir.txt index f7603cb53f4..3ed3b69eda8 100644 --- a/compiler/testData/ir/irText/declarations/parameters/delegatedMembers.fir.txt +++ b/compiler/testData/ir/irText/declarations/parameters/delegatedMembers.fir.txt @@ -62,7 +62,7 @@ FILE fqName: fileName:/delegatedMembers.kt FUN DELEGATED_MEMBER name:qux visibility:public modality:OPEN ($this:.Test.Test>, t:TT of .Test, x:X of .Test.qux) returnType:kotlin.Unit overridden: public abstract fun qux (t: T of .IBase, x: X of .IBase.qux): kotlin.Unit declared in .IBase - TYPE_PARAMETER DELEGATED_MEMBER name:X index:0 variance: superTypes:[] + TYPE_PARAMETER DELEGATED_MEMBER name:X index:0 variance: superTypes:[kotlin.Any?] $this: VALUE_PARAMETER DELEGATED_MEMBER name: type:.Test.Test> VALUE_PARAMETER DELEGATED_MEMBER name:t index:0 type:TT of .Test VALUE_PARAMETER DELEGATED_MEMBER name:x index:1 type:X of .Test.qux