diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt index cc5311b4a43..63be80096f5 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/ConversionUtils.kt @@ -309,8 +309,14 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( * And for this case we can pass isForDelegateProviderCall to this reference * generator function */ - fun thisRef(isForDelegateProviderCall: Boolean = false): FirExpression = + fun thisRef(forDispatchReceiver: Boolean = false): FirExpression = when { + isExtension && !forDispatchReceiver -> buildThisReceiverExpression { + source = fakeSource + calleeReference = buildImplicitThisReference { + boundSymbol = this@generateAccessorsByDelegate.symbol + } + } ownerSymbol != null -> buildThisReceiverExpression { source = fakeSource calleeReference = buildImplicitThisReference { @@ -321,12 +327,6 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( type = ownerSymbol.constructStarProjectedType(typeParameterNumber) } } - isExtension && !isForDelegateProviderCall -> buildThisReceiverExpression { - source = fakeSource - calleeReference = buildImplicitThisReference { - boundSymbol = this@generateAccessorsByDelegate.symbol - } - } else -> buildConstExpression(null, ConstantValueKind.Null, null) } @@ -336,7 +336,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( resolvedSymbol = delegateFieldSymbol } if (ownerSymbol != null) { - dispatchReceiver = thisRef() + dispatchReceiver = thisRef(forDispatchReceiver = true) } } @@ -373,7 +373,7 @@ fun FirPropertyBuilder.generateAccessorsByDelegate( source = fakeSource name = PROVIDE_DELEGATE } - argumentList = buildBinaryArgumentList(thisRef(isForDelegateProviderCall = true), propertyRef()) + argumentList = buildBinaryArgumentList(thisRef(forDispatchReceiver = true), propertyRef()) } delegate = delegateBuilder.build() if (stubMode) return diff --git a/compiler/testData/codegen/box/delegatedProperty/delegateForExtPropertyInClass.kt b/compiler/testData/codegen/box/delegatedProperty/delegateForExtPropertyInClass.kt index 03986df0169..7cdaca652eb 100644 --- a/compiler/testData/codegen/box/delegatedProperty/delegateForExtPropertyInClass.kt +++ b/compiler/testData/codegen/box/delegatedProperty/delegateForExtPropertyInClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR import kotlin.reflect.KProperty class Delegate { diff --git a/compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/mixedArgumentSizes.kt b/compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/mixedArgumentSizes.kt index 41a0a1ebd3e..5baa4cf3330 100644 --- a/compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/mixedArgumentSizes.kt +++ b/compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/mixedArgumentSizes.kt @@ -1,6 +1,5 @@ // !LANGUAGE: -NewInference -// IGNORE_BACKEND_FIR: JVM_IR inline operator fun Double.provideDelegate(thisRef: Any?, kProp: Any?) = this.toLong() inline operator fun Long.getValue(thisRef: Any?, kProp: Any?) = this.toInt() @@ -59,4 +58,4 @@ fun box(): String { x.test(intArray) return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/delegatedProperty/provideDelegate/memberExtension.kt b/compiler/testData/codegen/box/delegatedProperty/provideDelegate/memberExtension.kt index 2fb4088ed9d..b8f1051a749 100644 --- a/compiler/testData/codegen/box/delegatedProperty/provideDelegate/memberExtension.kt +++ b/compiler/testData/codegen/box/delegatedProperty/provideDelegate/memberExtension.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME object Host { @@ -13,4 +12,4 @@ object Host { val ok = "O".plusK } -fun box(): String = Host.ok \ No newline at end of file +fun box(): String = Host.ok diff --git a/compiler/testData/codegen/box/ir/serializationRegressions/deepGenericDelegatedProperty.kt b/compiler/testData/codegen/box/ir/serializationRegressions/deepGenericDelegatedProperty.kt index 9f682ba712d..db0654692ec 100644 --- a/compiler/testData/codegen/box/ir/serializationRegressions/deepGenericDelegatedProperty.kt +++ b/compiler/testData/codegen/box/ir/serializationRegressions/deepGenericDelegatedProperty.kt @@ -1,6 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM // WASM_MUTE_REASON: PROPERTY_REFERENCES -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: NATIVE //For KT-6020 @@ -59,4 +58,4 @@ fun box(): String { val p = Value("O", CR("K")) val rr = p.additionalText return rr.p1 + rr.p2 -} \ No newline at end of file +} diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.kt.txt b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.kt.txt deleted file mode 100644 index 175e23fdae8..00000000000 --- a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.kt.txt +++ /dev/null @@ -1,39 +0,0 @@ -object Host { - private constructor() /* primary */ { - super/*Any*/() - /* () */ - - } - - class StringDelegate { - constructor(s: String) /* primary */ { - super/*Any*/() - /* () */ - - } - - val s: String - field = s - get - - operator fun getValue(receiver: String, p: Any): String { - return receiver.plus(other = .()) - } - - } - - operator fun String.provideDelegate(host: Any?, p: Any): StringDelegate { - return StringDelegate(s = ) - } - - val String.plusK: String /* by */ - field = (, "K").provideDelegate(host = , p = Host::plusK) - get(): String { - return .#plusK$delegate.getValue(receiver = , p = Host::plusK) - } - - val ok: String - field = (, "O").() - get - -} diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt deleted file mode 100644 index d317677272b..00000000000 --- a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt +++ /dev/null @@ -1,102 +0,0 @@ -FILE fqName: fileName:/memberExtension.kt - CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Host - CONSTRUCTOR visibility:private <> () returnType:.Host [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' - CLASS CLASS name:StringDelegate modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Host.StringDelegate - CONSTRUCTOR visibility:public <> (s:kotlin.String) returnType:.Host.StringDelegate [primary] - VALUE_PARAMETER name:s index:0 type:kotlin.String - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:StringDelegate modality:FINAL visibility:public superTypes:[kotlin.Any]' - PROPERTY name:s visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private [final] - EXPRESSION_BODY - GET_VAR 's: kotlin.String declared in .Host.StringDelegate.' type=kotlin.String origin=INITIALIZE_PROPERTY_FROM_PARAMETER - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Host.StringDelegate) returnType:kotlin.String - correspondingProperty: PROPERTY name:s visibility:public modality:FINAL [val] - $this: VALUE_PARAMETER name: type:.Host.StringDelegate - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Host.StringDelegate' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String visibility:private [final]' type=kotlin.String origin=null - receiver: GET_VAR ': .Host.StringDelegate declared in .Host.StringDelegate.' type=.Host.StringDelegate origin=null - FUN name:getValue visibility:public modality:FINAL <> ($this:.Host.StringDelegate, receiver:kotlin.String, p:kotlin.Any) returnType:kotlin.String [operator] - $this: VALUE_PARAMETER name: type:.Host.StringDelegate - VALUE_PARAMETER name:receiver index:0 type:kotlin.String - VALUE_PARAMETER name:p index:1 type:kotlin.Any - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun getValue (receiver: kotlin.String, p: kotlin.Any): kotlin.String [operator] declared in .Host.StringDelegate' - CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin.String' type=kotlin.String origin=PLUS - $this: GET_VAR 'receiver: kotlin.String declared in .Host.StringDelegate.getValue' type=kotlin.String origin=null - other: CALL 'public final fun (): kotlin.String declared in .Host.StringDelegate' type=kotlin.String origin=GET_PROPERTY - $this: GET_VAR ': .Host.StringDelegate declared in .Host.StringDelegate.getValue' type=.Host.StringDelegate origin=null - 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: 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: 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: type:kotlin.Any - FUN name:provideDelegate visibility:public modality:FINAL <> ($this:.Host, $receiver:kotlin.String, host:kotlin.Any?, p:kotlin.Any) returnType:.Host.StringDelegate [operator] - $this: VALUE_PARAMETER name: type:.Host - $receiver: VALUE_PARAMETER name: type:kotlin.String - VALUE_PARAMETER name:host index:0 type:kotlin.Any? - VALUE_PARAMETER name:p index:1 type:kotlin.Any - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun provideDelegate (host: kotlin.Any?, p: kotlin.Any): .Host.StringDelegate [operator] declared in .Host' - CONSTRUCTOR_CALL 'public constructor (s: kotlin.String) [primary] declared in .Host.StringDelegate' type=.Host.StringDelegate origin=null - s: GET_VAR ': kotlin.String declared in .Host.provideDelegate' type=kotlin.String origin=null - PROPERTY name:plusK visibility:public modality:FINAL [delegated,val] - FIELD PROPERTY_DELEGATE name:plusK$delegate type:.Host.StringDelegate visibility:private [final] - EXPRESSION_BODY - CALL 'public final fun provideDelegate (host: kotlin.Any?, p: kotlin.Any): .Host.StringDelegate [operator] declared in .Host' type=.Host.StringDelegate origin=null - $this: GET_VAR ': .Host declared in .Host' type=.Host origin=null - $receiver: CONST String type=kotlin.String value="K" - host: GET_VAR ': .Host declared in .Host' type=.Host origin=null - p: PROPERTY_REFERENCE 'public final plusK: kotlin.String [delegated,val]' field=null getter='public final fun (): kotlin.String declared in .Host' setter=null type=kotlin.reflect.KProperty2.Host, kotlin.String> origin=PROPERTY_REFERENCE_FOR_DELEGATE - FUN DELEGATED_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Host, $receiver:kotlin.String) returnType:kotlin.String - correspondingProperty: PROPERTY name:plusK visibility:public modality:FINAL [delegated,val] - $this: VALUE_PARAMETER name: type:.Host - $receiver: VALUE_PARAMETER name: type:kotlin.String - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Host' - CALL 'public final fun getValue (receiver: kotlin.String, p: kotlin.Any): kotlin.String [operator] declared in .Host.StringDelegate' type=kotlin.String origin=null - $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:plusK$delegate type:.Host.StringDelegate visibility:private [final]' type=.Host.StringDelegate origin=null - receiver: GET_VAR ': .Host declared in .Host.' type=.Host origin=null - receiver: GET_VAR ': .Host declared in .Host.' type=.Host origin=null - p: PROPERTY_REFERENCE 'public final plusK: kotlin.String [delegated,val]' field=null getter='public final fun (): kotlin.String declared in .Host' setter=null type=kotlin.reflect.KProperty2.Host, kotlin.String> origin=PROPERTY_REFERENCE_FOR_DELEGATE - PROPERTY name:ok visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final] - EXPRESSION_BODY - CALL 'public final fun (): kotlin.String declared in .Host' type=kotlin.String origin=GET_PROPERTY - $this: GET_VAR ': .Host declared in .Host' type=.Host origin=null - $receiver: CONST String type=kotlin.String value="O" - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.String - correspondingProperty: PROPERTY name:ok visibility:public modality:FINAL [val] - $this: VALUE_PARAMETER name: type:.Host - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in .Host' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final]' type=kotlin.String origin=null - receiver: GET_VAR ': .Host declared in .Host.' type=.Host origin=null - 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: 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: 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: type:kotlin.Any diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.kt b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.kt index bf538dbb143..28bbeaa82c2 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.kt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL object Host { class StringDelegate(val s: String) { operator fun getValue(receiver: String, p: Any) = receiver + s diff --git a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.txt b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.txt index 21eccadcd6a..0787739c069 100644 --- a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.txt +++ b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.txt @@ -281,7 +281,7 @@ FILE fqName: fileName:/genericDelegatedDeepProperty.kt $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:deepO$delegate type:.additionalText$delegate..deepO$delegate..> visibility:private [final]' type=.additionalText$delegate..deepO$delegate..> origin=null receiver: TYPE_OP type=.additionalText$delegate. origin=IMPLICIT_CAST typeOperand=.additionalText$delegate. GET_VAR ': .additionalText$delegate..> declared in .additionalText$delegate..' type=.additionalText$delegate..> origin=null - t: GET_VAR ': .additionalText$delegate..> declared in .additionalText$delegate..' type=.additionalText$delegate..> origin=null + t: GET_VAR ': .Value., .CR.>> declared in .additionalText$delegate..' type=.Value., .CR.>> origin=null p: PROPERTY_REFERENCE 'private final deepO: T of . [delegated,val]' field=null getter='public final fun (): T of . declared in .additionalText$delegate.' setter=null type=kotlin.reflect.KProperty2<.Value., .CR.>>, *, T of .> origin=PROPERTY_REFERENCE_FOR_DELEGATE PROPERTY name:deepK visibility:private modality:FINAL [delegated,val] FIELD PROPERTY_DELEGATE name:deepK$delegate type:.additionalText$delegate..deepK$delegate..> visibility:private [final] @@ -328,7 +328,7 @@ FILE fqName: fileName:/genericDelegatedDeepProperty.kt $this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:deepK$delegate type:.additionalText$delegate..deepK$delegate..> visibility:private [final]' type=.additionalText$delegate..deepK$delegate..> origin=null receiver: TYPE_OP type=.additionalText$delegate. origin=IMPLICIT_CAST typeOperand=.additionalText$delegate. GET_VAR ': .additionalText$delegate..> declared in .additionalText$delegate..' type=.additionalText$delegate..> origin=null - t: GET_VAR ': .additionalText$delegate..> declared in .additionalText$delegate..' type=.additionalText$delegate..> origin=null + t: GET_VAR ': .Value., .CR.>> declared in .additionalText$delegate..' type=.Value., .CR.>> origin=null p: PROPERTY_REFERENCE 'private final deepK: T of . [delegated,val]' field=null getter='public final fun (): T of . declared in .additionalText$delegate.' setter=null type=kotlin.reflect.KProperty2<.Value., .CR.>>, *, T of .> origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN name:getValue visibility:public modality:FINAL <> ($this:.additionalText$delegate..>, t:.Value., .CR.>>, p:kotlin.reflect.KProperty<*>) returnType:.P., T of .> [operator] overridden: