diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirBodyResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirBodyResolveTransformer.kt index 30a9719dacf..fa7cf025a2e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirBodyResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirBodyResolveTransformer.kt @@ -675,18 +675,30 @@ open class FirBodyResolveTransformer( } } - override fun transformPropertyAccessor(propertyAccessor: FirPropertyAccessor, data: Any?): CompositeTransformResult { - if (propertyAccessor is FirDefaultPropertyAccessor || propertyAccessor.body == null) { - return transformFunction(propertyAccessor, data) + private fun transformAccessor( + accessor: FirPropertyAccessor, + enhancedTypeRef: FirTypeRef, + owner: FirVariable<*> + ) { + if (accessor is FirDefaultPropertyAccessor || accessor.body == null) { + transformFunction(accessor, enhancedTypeRef) } - val returnTypeRef = propertyAccessor.returnTypeRef - if (returnTypeRef is FirImplicitTypeRef && data !is FirResolvedTypeRef) { - propertyAccessor.transformReturnTypeRef(StoreType, FirComputingImplicitTypeRef) + val returnTypeRef = accessor.returnTypeRef + if (returnTypeRef is FirImplicitTypeRef && enhancedTypeRef !is FirResolvedTypeRef) { + accessor.transformReturnTypeRef(StoreType, FirComputingImplicitTypeRef) } - return if (data is FirResolvedTypeRef && returnTypeRef !is FirResolvedTypeRef) { - transformFunctionWithGivenSignature(propertyAccessor, data) + val expectedReturnTypeRef = if (enhancedTypeRef is FirResolvedTypeRef && returnTypeRef !is FirResolvedTypeRef) { + enhancedTypeRef } else { - transformFunctionWithGivenSignature(propertyAccessor, returnTypeRef) + returnTypeRef + } + val receiverTypeRef = owner.receiverTypeRef + if (receiverTypeRef != null) { + withLabelAndReceiverType(owner.name, owner, receiverTypeRef.coneTypeUnsafe()) { + transformFunctionWithGivenSignature(accessor, expectedReturnTypeRef, receiverTypeRef) + } + } else { + transformFunctionWithGivenSignature(accessor, expectedReturnTypeRef) } } @@ -732,14 +744,16 @@ open class FirBodyResolveTransformer( private fun > FirVariable.transformAccessors() { var enhancedTypeRef = returnTypeRef - getter?.transform(this@FirBodyResolveTransformer, enhancedTypeRef) + getter?.let { + transformAccessor(it, enhancedTypeRef, this) + } if (returnTypeRef is FirImplicitTypeRef) { storeVariableReturnType(this) enhancedTypeRef = returnTypeRef } setter?.let { it.valueParameters[0].transformReturnTypeRef(StoreType, enhancedTypeRef) - it.transform(this@FirBodyResolveTransformer, enhancedTypeRef) + transformAccessor(it, enhancedTypeRef, this) } } @@ -904,6 +918,9 @@ open class FirBodyResolveTransformer( is FirFunction<*> -> { ImplicitExtensionReceiverValue(owner.symbol, type, session, scopeSession) } + is FirVariable<*> -> { + ImplicitExtensionReceiverValue(owner.symbol, type, session, scopeSession) + } else -> { throw IllegalArgumentException("Incorrect label & receiver owner: ${owner.javaClass}") } diff --git a/compiler/fir/resolve/testData/resolve/problems2.txt b/compiler/fir/resolve/testData/resolve/problems2.txt index 344f3c4f36d..9fb5f9b2959 100644 --- a/compiler/fir/resolve/testData/resolve/problems2.txt +++ b/compiler/fir/resolve/testData/resolve/problems2.txt @@ -72,7 +72,7 @@ FILE: problems2.kt public get(): R|kotlin/String| } - public final val R|KonanTarget|.presetName: - public get(): { - ^ this#.# + public final val R|KonanTarget|.presetName: R|kotlin/String| + public get(): R|kotlin/String| { + ^ this@R|/presetName|.R|/KonanTarget.name| } diff --git a/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt b/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt index b062c71abef..55890ac5dd7 100644 --- a/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt +++ b/compiler/fir/resolve/testData/resolve/typeParameterInPropertyReceiver.txt @@ -1,5 +1,5 @@ FILE: typeParameterInPropertyReceiver.kt public final val R|T|.self: R|T| public get(): R|T| { - ^ this# + ^ this@R|/self| } diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt index 9cd762fd241..9d37c28e20c 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt @@ -61,26 +61,27 @@ FILE fqName: fileName:/memberExtension.kt CALL 'public final fun provideDelegate (host: kotlin.Any?, p: kotlin.Any): .Host.StringDelegate declared in .Host' type=.Host.StringDelegate origin=null $this: GET_VAR ': .Host declared in .Host' type=.Host origin=null host: GET_VAR ': .Host declared in .Host' type=.Host origin=null - p: PROPERTY_REFERENCE 'public final plusK: IrErrorType [delegated,val]' field=null getter='public final fun (): IrErrorType declared in .Host' setter=null type=kotlin.reflect.KProperty<*> origin=null - FUN DELEGATED_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Host) returnType:IrErrorType + 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.KProperty<*> origin=null + FUN DELEGATED_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Host) returnType:kotlin.String correspondingProperty: PROPERTY name:plusK visibility:public modality:FINAL [delegated,val] $this: VALUE_PARAMETER name: type:.Host BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in .Host' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - GET_VAR ': .Host declared in .Host' type=.Host origin=null - PROPERTY_REFERENCE 'public final plusK: IrErrorType [delegated,val]' field='FIELD DELEGATE name:plusK$delegate type:.Host.StringDelegate visibility:private [final]' getter='public final fun (): IrErrorType declared in .Host' setter=null type=kotlin.reflect.KProperty<*> origin=null + 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 declared in .Host.StringDelegate' type=kotlin.String origin=null + $this: GET_FIELD 'FIELD DELEGATE name:plusK$delegate type:.Host.StringDelegate visibility:private [final]' type=.Host.StringDelegate origin=GET_PROPERTY + receiver: ERROR_CALL 'Unresolved reference: this@R|/Host.plusK|' type=kotlin.String + p: PROPERTY_REFERENCE 'public final plusK: kotlin.String [delegated,val]' field='FIELD DELEGATE name:plusK$delegate type:.Host.StringDelegate visibility:private [final]' getter='public final fun (): kotlin.String declared in .Host' setter=null type=kotlin.reflect.KProperty<*> origin=null PROPERTY name:ok visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:ok type:IrErrorType visibility:private [final] + FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final] EXPRESSION_BODY - CALL 'public final fun (): IrErrorType declared in .Host' type=IrErrorType origin=null + CALL 'public final fun (): kotlin.String declared in .Host' type=kotlin.String origin=null $this: GET_VAR ': .Host declared in .Host' type=.Host origin=null - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Host) returnType:IrErrorType + 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 (): IrErrorType declared in .Host' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:ok type:IrErrorType visibility:private [final]' type=IrErrorType origin=null + 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 overridden: diff --git a/compiler/testData/ir/irText/expressions/castToTypeParameter.fir.txt b/compiler/testData/ir/irText/expressions/castToTypeParameter.fir.txt index a112679f726..fbef08ec6bd 100644 --- a/compiler/testData/ir/irText/expressions/castToTypeParameter.fir.txt +++ b/compiler/testData/ir/irText/expressions/castToTypeParameter.fir.txt @@ -19,7 +19,7 @@ FILE fqName: fileName:/castToTypeParameter.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): T of declared in ' TYPE_OP type=T of origin=CAST typeOperand=T of - ERROR_CALL 'Unresolved reference: this#' type=IrErrorType + ERROR_CALL 'Unresolved reference: this@R|/castExtVal|' type=T of CLASS CLASS name:Host modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Host TYPE_PARAMETER name:T index:0 variance: superTypes:[] @@ -64,7 +64,7 @@ FILE fqName: fileName:/castToTypeParameter.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): T of .Host declared in .Host' TYPE_OP type=T of .Host origin=CAST typeOperand=T of .Host - GET_VAR ': .Host declared in .Host' type=.Host.Host> origin=null + ERROR_CALL 'Unresolved reference: this@R|/Host.castMemberExtVal|' type=kotlin.Any PROPERTY name:castGenericMemberExtVal visibility:public modality:FINAL [val] FUN name: visibility:public modality:FINAL <> ($this:.Host) returnType:TV of correspondingProperty: PROPERTY name:castGenericMemberExtVal visibility:public modality:FINAL [val] @@ -72,7 +72,7 @@ FILE fqName: fileName:/castToTypeParameter.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): TV of declared in .Host' TYPE_OP type=TV of origin=CAST typeOperand=TV of - GET_VAR ': .Host declared in .Host' type=T of .Host origin=null + ERROR_CALL 'Unresolved reference: this@R|/Host.castGenericMemberExtVal|' type=TV of FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any diff --git a/compiler/testData/ir/irText/expressions/genericPropertyCall.fir.txt b/compiler/testData/ir/irText/expressions/genericPropertyCall.fir.txt index 3d461fab7df..d6a7e283ae1 100644 --- a/compiler/testData/ir/irText/expressions/genericPropertyCall.fir.txt +++ b/compiler/testData/ir/irText/expressions/genericPropertyCall.fir.txt @@ -1,17 +1,16 @@ FILE fqName: fileName:/genericPropertyCall.kt PROPERTY name:id visibility:public modality:FINAL [val] - FUN name: visibility:public modality:FINAL <> () returnType:IrErrorType + FUN name: visibility:public modality:FINAL <> () returnType:T of correspondingProperty: PROPERTY name:id visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: this#' type=IrErrorType + RETURN type=kotlin.Nothing from='public final fun (): T of declared in ' + ERROR_CALL 'Unresolved reference: this@R|/id|' type=T of PROPERTY name:test visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:private [final,static] + FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String visibility:private [final,static] EXPRESSION_BODY - ERROR_CALL 'Unresolved reference: R?C|/id|' type=IrErrorType - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType + CALL 'public final fun (): T of declared in ' type=kotlin.String origin=null + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.String correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:IrErrorType visibility:private [final,static]' type=IrErrorType origin=null - + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String visibility:private [final,static]' type=kotlin.String origin=null diff --git a/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.txt b/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.txt index 3de18c915d3..880a15ef837 100644 --- a/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.txt +++ b/compiler/testData/ir/irText/expressions/genericPropertyRef.fir.txt @@ -163,13 +163,13 @@ FILE fqName: fileName:/genericPropertyRef.kt correspondingProperty: PROPERTY name:bar visibility:public modality:FINAL [var] BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): T of declared in ' - ERROR_CALL 'Unresolved reference: this#' type=IrErrorType + ERROR_CALL 'Unresolved reference: this@R|/bar|' type=T of FUN name: visibility:public modality:FINAL <> (value:T of ) returnType:kotlin.Unit correspondingProperty: PROPERTY name:bar visibility:public modality:FINAL [var] VALUE_PARAMETER name:value index:0 type:T of BLOCK_BODY SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:recivier type:kotlin.Any? visibility:private [static]' type=kotlin.Unit origin=null - value: ERROR_CALL 'Unresolved reference: this#' type=IrErrorType + value: ERROR_CALL 'Unresolved reference: this@R|/bar|' type=T of SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:value2 type:kotlin.Any? visibility:private [static]' type=kotlin.Unit origin=null value: GET_VAR 'value: T of declared in .' type=T of origin=null PROPERTY name:barRef visibility:public modality:FINAL [val] diff --git a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.txt b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.txt index c2d0273e558..71c2a070f3b 100644 --- a/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.txt +++ b/compiler/testData/ir/irText/expressions/implicitCastToTypeParameter.fir.txt @@ -33,11 +33,11 @@ FILE fqName: fileName:/implicitCastToTypeParameter.kt correspondingProperty: PROPERTY name:asT visibility:public modality:FINAL [val] BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): T of ? declared in ' - WHEN type=IrErrorType origin=IF + WHEN type=T of ? origin=IF BRANCH if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of - ERROR_CALL 'Unresolved reference: this#' type=IrErrorType - then: ERROR_CALL 'Unresolved reference: this#' type=IrErrorType + ERROR_CALL 'Unresolved reference: this@R|/asT|' type=.Foo> + then: ERROR_CALL 'Unresolved reference: this@R|/asT|' type=T of BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Null type=kotlin.Nothing? value=null diff --git a/compiler/testData/ir/irText/expressions/useImportedMember.fir.txt b/compiler/testData/ir/irText/expressions/useImportedMember.fir.txt index 89644a5da70..30b1adb05db 100644 --- a/compiler/testData/ir/irText/expressions/useImportedMember.fir.txt +++ b/compiler/testData/ir/irText/expressions/useImportedMember.fir.txt @@ -40,7 +40,7 @@ FILE fqName: fileName:/useImportedMember.kt $this: VALUE_PARAMETER name: type:.BaseClass BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): T of declared in .BaseClass' - GET_VAR ': .BaseClass declared in .BaseClass' type=.BaseClass origin=null + ERROR_CALL 'Unresolved reference: this@R|/BaseClass.fromClass|' type=T of FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any @@ -117,7 +117,7 @@ FILE fqName: fileName:/useImportedMember.kt $this: VALUE_PARAMETER name: type:.C BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): T of declared in .C' - GET_VAR ': .C declared in .C' type=.C origin=null + ERROR_CALL 'Unresolved reference: this@R|/C.g2|' type=T of PROPERTY FAKE_OVERRIDE name:fromClass visibility:public modality:FINAL [val] FUN FAKE_OVERRIDE name: visibility:public modality:FINAL <> ($this:.C) returnType:T of correspondingProperty: PROPERTY FAKE_OVERRIDE name:fromClass visibility:public modality:FINAL [val] diff --git a/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.fir.txt b/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.fir.txt index 5ca90b2c7d0..ddbffd26107 100644 --- a/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.fir.txt +++ b/compiler/testData/ir/irText/expressions/variableAsFunctionCallWithGenerics.fir.txt @@ -4,10 +4,10 @@ FILE fqName: fileName:/variableAsFunctionCallWithGenerics.kt correspondingProperty: PROPERTY name:gk visibility:public modality:FINAL [val] BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function0> declared in ' - FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:IrErrorType + FUN_EXPR type=kotlin.Function0> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:T of BLOCK_BODY - ERROR_CALL 'Unresolved reference: this#' type=IrErrorType + ERROR_CALL 'Unresolved reference: this@R|/gk|' type=T of FUN name:testGeneric1 visibility:public modality:FINAL <> (x:kotlin.String) returnType:T of VALUE_PARAMETER name:x index:0 type:kotlin.String BLOCK_BODY @@ -19,11 +19,11 @@ FILE fqName: fileName:/variableAsFunctionCallWithGenerics.kt correspondingProperty: PROPERTY name:kt26531Val visibility:public modality:FINAL [val] BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function0> declared in ' - FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN name: visibility:local modality:FINAL <> () returnType:IrErrorType + FUN_EXPR type=kotlin.Function0> origin=LAMBDA + FUN name: visibility:local modality:FINAL <> () returnType:T of BLOCK_BODY - RETURN type=kotlin.Nothing from='local final fun (): IrErrorType declared in .' - ERROR_CALL 'Unresolved reference: this#' type=IrErrorType + RETURN type=kotlin.Nothing from='local final fun (): T of declared in .' + ERROR_CALL 'Unresolved reference: this@R|/kt26531Val|' type=T of FUN name:kt26531 visibility:public modality:FINAL <> () returnType:T of BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun kt26531 (): T of declared in ' diff --git a/compiler/testData/ir/irText/stubs/jdkClassSyntheticProperty.fir.txt b/compiler/testData/ir/irText/stubs/jdkClassSyntheticProperty.fir.txt index e36a194a51b..e709fd92291 100644 --- a/compiler/testData/ir/irText/stubs/jdkClassSyntheticProperty.fir.txt +++ b/compiler/testData/ir/irText/stubs/jdkClassSyntheticProperty.fir.txt @@ -1,7 +1,8 @@ FILE fqName: fileName:/jdkClassSyntheticProperty.kt PROPERTY name:test visibility:public modality:FINAL [val] - FUN name: visibility:public modality:FINAL <> () returnType:IrErrorType + FUN name: visibility:public modality:FINAL <> () returnType:kotlin.Array correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Array declared in ' + CALL 'public open fun getDeclaredFields (): kotlin.Array declared in java.lang.Class' type=kotlin.Array origin=GET_PROPERTY + $this: ERROR_CALL 'Unresolved reference: this@R|/test|' type=java.lang.Class<*>