FIR: provide receiver for accessor of extension property

This commit is contained in:
Mikhail Glukhikh
2019-09-25 14:42:25 +03:00
parent 0d4ca06372
commit da7d5d5702
11 changed files with 73 additions and 55 deletions
@@ -675,18 +675,30 @@ open class FirBodyResolveTransformer(
}
}
override fun transformPropertyAccessor(propertyAccessor: FirPropertyAccessor, data: Any?): CompositeTransformResult<FirDeclaration> {
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 <F : FirVariable<F>> FirVariable<F>.transformAccessors() {
var enhancedTypeRef = returnTypeRef
getter?.transform<FirDeclaration, Any?>(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<FirDeclaration, Any?>(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}")
}
+3 -3
View File
@@ -72,7 +72,7 @@ FILE: problems2.kt
public get(): R|kotlin/String|
}
public final val R|KonanTarget|.presetName: <ERROR TYPE REF: Unresolved name: name>
public get(): <ERROR TYPE REF: Unresolved name: name> {
^ this#.<Unresolved name: name>#
public final val R|KonanTarget|.presetName: R|kotlin/String|
public get(): R|kotlin/String| {
^ this@R|/presetName|.R|/KonanTarget.name|
}
@@ -1,5 +1,5 @@
FILE: typeParameterInPropertyReceiver.kt
public final val <T : R|kotlin/Any|> R|T|.self: R|T|
public get(): R|T| {
^ this#
^ this@R|/self|
}
@@ -61,26 +61,27 @@ FILE fqName:<root> fileName:/memberExtension.kt
CALL 'public final fun provideDelegate (host: kotlin.Any?, p: kotlin.Any): <root>.Host.StringDelegate declared in <root>.Host' type=<root>.Host.StringDelegate origin=null
$this: GET_VAR '<this>: <root>.Host declared in <root>.Host' type=<root>.Host origin=null
host: GET_VAR '<this>: <root>.Host declared in <root>.Host' type=<root>.Host origin=null
p: PROPERTY_REFERENCE 'public final plusK: IrErrorType [delegated,val]' field=null getter='public final fun <get-plusK> (): IrErrorType declared in <root>.Host' setter=null type=kotlin.reflect.KProperty<*> origin=null
FUN DELEGATED_PROPERTY_ACCESSOR name:<get-plusK> visibility:public modality:FINAL <> ($this:<root>.Host) returnType:IrErrorType
p: PROPERTY_REFERENCE 'public final plusK: kotlin.String [delegated,val]' field=null getter='public final fun <get-plusK> (): kotlin.String declared in <root>.Host' setter=null type=kotlin.reflect.KProperty<*> origin=null
FUN DELEGATED_PROPERTY_ACCESSOR name:<get-plusK> visibility:public modality:FINAL <> ($this:<root>.Host) returnType:kotlin.String
correspondingProperty: PROPERTY name:plusK visibility:public modality:FINAL [delegated,val]
$this: VALUE_PARAMETER name:<this> type:<root>.Host
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-plusK> (): IrErrorType declared in <root>.Host'
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/Host.StringDelegate.getValue]>#' type=IrErrorType
GET_VAR '<this>: <root>.Host declared in <root>.Host' type=<root>.Host origin=null
PROPERTY_REFERENCE 'public final plusK: IrErrorType [delegated,val]' field='FIELD DELEGATE name:plusK$delegate type:<root>.Host.StringDelegate visibility:private [final]' getter='public final fun <get-plusK> (): IrErrorType declared in <root>.Host' setter=null type=kotlin.reflect.KProperty<*> origin=null
RETURN type=kotlin.Nothing from='public final fun <get-plusK> (): kotlin.String declared in <root>.Host'
CALL 'public final fun getValue (receiver: kotlin.String, p: kotlin.Any): kotlin.String declared in <root>.Host.StringDelegate' type=kotlin.String origin=null
$this: GET_FIELD 'FIELD DELEGATE name:plusK$delegate type:<root>.Host.StringDelegate visibility:private [final]' type=<root>.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:<root>.Host.StringDelegate visibility:private [final]' getter='public final fun <get-plusK> (): kotlin.String declared in <root>.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 <get-plusK> (): IrErrorType declared in <root>.Host' type=IrErrorType origin=null
CALL 'public final fun <get-plusK> (): kotlin.String declared in <root>.Host' type=kotlin.String origin=null
$this: GET_VAR '<this>: <root>.Host declared in <root>.Host' type=<root>.Host origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-ok> visibility:public modality:FINAL <> ($this:<root>.Host) returnType:IrErrorType
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-ok> visibility:public modality:FINAL <> ($this:<root>.Host) returnType:kotlin.String
correspondingProperty: PROPERTY name:ok visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Host
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-ok> (): IrErrorType declared in <root>.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 <get-ok> (): kotlin.String declared in <root>.Host'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:ok type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
receiver: GET_VAR '<this>: <root>.Host declared in <root>.Host.<get-ok>' type=<root>.Host origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean
overridden:
@@ -19,7 +19,7 @@ FILE fqName:<root> fileName:/castToTypeParameter.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-castExtVal> (): T of <uninitialized parent> declared in <root>'
TYPE_OP type=T of <uninitialized parent> origin=CAST typeOperand=T of <uninitialized parent>
ERROR_CALL 'Unresolved reference: this#' type=IrErrorType
ERROR_CALL 'Unresolved reference: this@R|/castExtVal|' type=T of <uninitialized parent>
CLASS CLASS name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Host
TYPE_PARAMETER name:T index:0 variance: superTypes:[]
@@ -64,7 +64,7 @@ FILE fqName:<root> fileName:/castToTypeParameter.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-castMemberExtVal> (): T of <root>.Host declared in <root>.Host'
TYPE_OP type=T of <root>.Host origin=CAST typeOperand=T of <root>.Host
GET_VAR '<this>: <root>.Host declared in <root>.Host' type=<root>.Host<T of <root>.Host> origin=null
ERROR_CALL 'Unresolved reference: this@R|/Host.castMemberExtVal|' type=kotlin.Any
PROPERTY name:castGenericMemberExtVal visibility:public modality:FINAL [val]
FUN name:<get-castGenericMemberExtVal> visibility:public modality:FINAL <> ($this:<root>.Host) returnType:TV of <uninitialized parent>
correspondingProperty: PROPERTY name:castGenericMemberExtVal visibility:public modality:FINAL [val]
@@ -72,7 +72,7 @@ FILE fqName:<root> fileName:/castToTypeParameter.kt
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-castGenericMemberExtVal> (): TV of <uninitialized parent> declared in <root>.Host'
TYPE_OP type=TV of <uninitialized parent> origin=CAST typeOperand=TV of <uninitialized parent>
GET_VAR '<this>: <root>.Host declared in <root>.Host' type=T of <root>.Host origin=null
ERROR_CALL 'Unresolved reference: this@R|/Host.castGenericMemberExtVal|' type=TV of <uninitialized parent>
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
@@ -1,17 +1,16 @@
FILE fqName:<root> fileName:/genericPropertyCall.kt
PROPERTY name:id visibility:public modality:FINAL [val]
FUN name:<get-id> visibility:public modality:FINAL <> () returnType:IrErrorType
FUN name:<get-id> visibility:public modality:FINAL <> () returnType:T of <uninitialized parent>
correspondingProperty: PROPERTY name:id visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-id> (): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: this#' type=IrErrorType
RETURN type=kotlin.Nothing from='public final fun <get-id> (): T of <uninitialized parent> declared in <root>'
ERROR_CALL 'Unresolved reference: this@R|/id|' type=T of <uninitialized parent>
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:<get-test> visibility:public modality:FINAL <> () returnType:IrErrorType
CALL 'public final fun <get-id> (): T of <uninitialized parent> declared in <root>' type=kotlin.String origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> 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 <get-test> (): IrErrorType declared in <root>'
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 <get-test> (): kotlin.String declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String visibility:private [final,static]' type=kotlin.String origin=null
@@ -163,13 +163,13 @@ FILE fqName:<root> fileName:/genericPropertyRef.kt
correspondingProperty: PROPERTY name:bar visibility:public modality:FINAL [var]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-bar> (): T of <uninitialized parent> declared in <root>'
ERROR_CALL 'Unresolved reference: this#' type=IrErrorType
ERROR_CALL 'Unresolved reference: this@R|/bar|' type=T of <uninitialized parent>
FUN name:<set-bar> visibility:public modality:FINAL <> (value:T of <uninitialized parent>) returnType:kotlin.Unit
correspondingProperty: PROPERTY name:bar visibility:public modality:FINAL [var]
VALUE_PARAMETER name:value index:0 type:T of <uninitialized parent>
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 <uninitialized parent>
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 <uninitialized parent> declared in <root>.<set-bar>' type=T of <uninitialized parent> origin=null
PROPERTY name:barRef visibility:public modality:FINAL [val]
@@ -33,11 +33,11 @@ FILE fqName:<root> fileName:/implicitCastToTypeParameter.kt
correspondingProperty: PROPERTY name:asT visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-asT> (): T of <uninitialized parent>? declared in <root>'
WHEN type=IrErrorType origin=IF
WHEN type=T of <uninitialized parent>? origin=IF
BRANCH
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of <uninitialized parent>
ERROR_CALL 'Unresolved reference: this#' type=IrErrorType
then: ERROR_CALL 'Unresolved reference: this#' type=IrErrorType
ERROR_CALL 'Unresolved reference: this@R|/asT|' type=<root>.Foo<T of <uninitialized parent>>
then: ERROR_CALL 'Unresolved reference: this@R|/asT|' type=T of <uninitialized parent>
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Null type=kotlin.Nothing? value=null
@@ -40,7 +40,7 @@ FILE fqName:<root> fileName:/useImportedMember.kt
$this: VALUE_PARAMETER name:<this> type:<root>.BaseClass
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-fromClass> (): T of <uninitialized parent> declared in <root>.BaseClass'
GET_VAR '<this>: <root>.BaseClass declared in <root>.BaseClass' type=<root>.BaseClass origin=null
ERROR_CALL 'Unresolved reference: this@R|/BaseClass.fromClass|' type=T of <uninitialized parent>
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:<root> fileName:/useImportedMember.kt
$this: VALUE_PARAMETER name:<this> type:<root>.C
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-g2> (): T of <uninitialized parent> declared in <root>.C'
GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.C origin=null
ERROR_CALL 'Unresolved reference: this@R|/C.g2|' type=T of <uninitialized parent>
PROPERTY FAKE_OVERRIDE name:fromClass visibility:public modality:FINAL [val]
FUN FAKE_OVERRIDE name:<get-fromClass> visibility:public modality:FINAL <> ($this:<root>.C) returnType:T of <uninitialized parent>
correspondingProperty: PROPERTY FAKE_OVERRIDE name:fromClass visibility:public modality:FINAL [val]
@@ -4,10 +4,10 @@ FILE fqName:<root> fileName:/variableAsFunctionCallWithGenerics.kt
correspondingProperty: PROPERTY name:gk visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-gk> (): kotlin.Function0<T of <uninitialized parent>> declared in <root>'
FUN_EXPR type=kotlin.Function0<IrErrorType> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:IrErrorType
FUN_EXPR type=kotlin.Function0<T of <uninitialized parent>> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:T of <uninitialized parent>
BLOCK_BODY
ERROR_CALL 'Unresolved reference: this#' type=IrErrorType
ERROR_CALL 'Unresolved reference: this@R|/gk|' type=T of <uninitialized parent>
FUN name:testGeneric1 visibility:public modality:FINAL <> (x:kotlin.String) returnType:T of <uninitialized parent>
VALUE_PARAMETER name:x index:0 type:kotlin.String
BLOCK_BODY
@@ -19,11 +19,11 @@ FILE fqName:<root> fileName:/variableAsFunctionCallWithGenerics.kt
correspondingProperty: PROPERTY name:kt26531Val visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-kt26531Val> (): kotlin.Function0<T of <uninitialized parent>> declared in <root>'
FUN_EXPR type=kotlin.Function0<IrErrorType> origin=LAMBDA
FUN name:<no name provided> visibility:local modality:FINAL <> () returnType:IrErrorType
FUN_EXPR type=kotlin.Function0<T of <uninitialized parent>> origin=LAMBDA
FUN name:<no name provided> visibility:local modality:FINAL <> () returnType:T of <uninitialized parent>
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <no name provided> (): IrErrorType declared in <root>.<get-kt26531Val>'
ERROR_CALL 'Unresolved reference: this#' type=IrErrorType
RETURN type=kotlin.Nothing from='local final fun <no name provided> (): T of <uninitialized parent> declared in <root>.<get-kt26531Val>'
ERROR_CALL 'Unresolved reference: this@R|/kt26531Val|' type=T of <uninitialized parent>
FUN name:kt26531 visibility:public modality:FINAL <> () returnType:T of <uninitialized parent>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun kt26531 (): T of <uninitialized parent> declared in <root>'
@@ -1,7 +1,8 @@
FILE fqName:<root> fileName:/jdkClassSyntheticProperty.kt
PROPERTY name:test visibility:public modality:FINAL [val]
FUN name:<get-test> visibility:public modality:FINAL <> () returnType:IrErrorType
FUN name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.Array<java.lang.reflect.Field?>
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-test> (): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Unresolved name: declaredFields>#' type=IrErrorType
RETURN type=kotlin.Nothing from='public final fun <get-test> (): kotlin.Array<java.lang.reflect.Field?> declared in <root>'
CALL 'public open fun getDeclaredFields (): kotlin.Array<java.lang.reflect.Field?> declared in java.lang.Class' type=kotlin.Array<java.lang.reflect.Field?> origin=GET_PROPERTY
$this: ERROR_CALL 'Unresolved reference: this@R|/test|' type=java.lang.Class<*>