diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 221cb303be1..5eb1a1b5561 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -793,11 +793,11 @@ class Fir2IrVisitor( } } - private fun FirQualifiedAccess.findIrDispatchReceiver(): IrExpression = findIrReceiver(isDispatch = true) + private fun FirQualifiedAccess.findIrDispatchReceiver(): IrExpression? = findIrReceiver(isDispatch = true) - private fun FirQualifiedAccess.findIrExtensionReceiver(): IrExpression = findIrReceiver(isDispatch = false) + private fun FirQualifiedAccess.findIrExtensionReceiver(): IrExpression? = findIrReceiver(isDispatch = false) - private fun FirQualifiedAccess.findIrReceiver(isDispatch: Boolean): IrExpression { + private fun FirQualifiedAccess.findIrReceiver(isDispatch: Boolean): IrExpression? { val firReceiver = if (isDispatch) dispatchReceiver else extensionReceiver return firReceiver.takeIf { it !is FirNoReceiverExpression }?.toIrExpression() ?: explicitReceiver?.toIrExpression() // NB: this applies to the situation when call is unresolved @@ -813,12 +813,14 @@ class Fir2IrVisitor( val irClass = declarationStorage.getIrClass(firClass, setParent = false) IrGetObjectValueImpl(startOffset, endOffset, irClass.defaultType, irClass.symbol) } - } ?: run { - val name = if (isDispatch) "Dispatch" else "Extension" - throw AssertionError( - "$name receiver expected: ${render()} to ${calleeReference.render()}" - ) } + // TODO: uncomment after fixing KT-35730 +// ?: run { +// val name = if (isDispatch) "Dispatch" else "Extension" +// throw AssertionError( +// "$name receiver expected: ${render()} to ${calleeReference.render()}" +// ) +// } } private fun IrExpression.applyReceivers(qualifiedAccess: FirQualifiedAccess): IrExpression { @@ -835,8 +837,7 @@ class Fir2IrVisitor( is IrFieldExpressionBase -> { val ownerField = symbol.owner if (!ownerField.isStatic) { - receiver = qualifiedAccess.dispatchReceiver.takeIf { it !is FirNoReceiverExpression }?.toIrExpression() - ?: qualifiedAccess.explicitReceiver?.toIrExpression() + receiver = qualifiedAccess.findIrDispatchReceiver() } this } diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt index 2f64b07894c..cc379657706 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt @@ -69,6 +69,7 @@ FILE fqName: fileName:/memberExtension.kt 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 DELEGATE name:plusK$delegate type:.Host.StringDelegate visibility:private [final]' type=.Host.StringDelegate origin=GET_PROPERTY + receiver: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Host 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] diff --git a/compiler/testData/ir/irText/expressions/objectReference.fir.txt b/compiler/testData/ir/irText/expressions/objectReference.fir.txt index f0935cc3e55..c22db1dff89 100644 --- a/compiler/testData/ir/irText/expressions/objectReference.fir.txt +++ b/compiler/testData/ir/irText/expressions/objectReference.fir.txt @@ -49,6 +49,7 @@ FILE fqName: fileName:/objectReference.kt ANONYMOUS_INITIALIZER isStatic=false BLOCK_BODY SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:counter type:kotlin.Int visibility:private' type=kotlin.Unit origin=null + receiver: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z value: CONST Int type=kotlin.Int value=1 CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z @@ -61,6 +62,7 @@ FILE fqName: fileName:/objectReference.kt $this: VALUE_PARAMETER name: type:.Z.Nested BLOCK_BODY SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:counter type:kotlin.Int visibility:private' type=kotlin.Unit origin=null + receiver: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z value: CONST Int type=kotlin.Int value=1 CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z diff --git a/compiler/testData/ir/irText/expressions/useImportedMember.fir.txt b/compiler/testData/ir/irText/expressions/useImportedMember.fir.txt index ac247882ff5..d0ac4512d2d 100644 --- a/compiler/testData/ir/irText/expressions/useImportedMember.fir.txt +++ b/compiler/testData/ir/irText/expressions/useImportedMember.fir.txt @@ -155,7 +155,7 @@ FILE fqName: fileName:/useImportedMember.kt if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun f (s: kotlin.Int): kotlin.Int declared in .C' type=kotlin.Int origin=null - $this: GET_VAR ': .C declared in .C' type=.C origin=null + $this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[.BaseClass; .I]' type=.C s: CONST Int type=kotlin.Int value=1 arg1: CONST Int type=kotlin.Int value=1 then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' @@ -165,7 +165,7 @@ FILE fqName: fileName:/useImportedMember.kt if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun f (s: kotlin.String): kotlin.Int declared in .C' type=kotlin.Int origin=null - $this: GET_VAR ': .C declared in .C' type=.C origin=null + $this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[.BaseClass; .I]' type=.C s: CONST String type=kotlin.String value="s" arg1: CONST Int type=kotlin.Int value=2 then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' @@ -175,7 +175,7 @@ FILE fqName: fileName:/useImportedMember.kt if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun f (): kotlin.Int declared in .C' type=kotlin.Int origin=null - $this: GET_VAR ': .C declared in .C' type=.C origin=null + $this: CONST Boolean type=kotlin.Boolean value=true arg1: CONST Int type=kotlin.Int value=3 then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' CONST String type=kotlin.String value="3" @@ -184,19 +184,19 @@ FILE fqName: fileName:/useImportedMember.kt if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun (): kotlin.Int declared in .C' type=kotlin.Int origin=null - $this: GET_VAR ': .C declared in .C' type=.C origin=null + $this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[.BaseClass; .I]' type=.C arg1: CONST Int type=kotlin.Int value=4 then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' CONST String type=kotlin.String value="4" SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:p type:kotlin.Int visibility:private' type=kotlin.Unit origin=null - receiver: GET_VAR ': .C declared in .C' type=.C origin=null + receiver: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[.BaseClass; .I]' type=.C value: CONST Int type=kotlin.Int value=5 WHEN type=kotlin.Unit origin=IF BRANCH if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun (): kotlin.Int declared in .C' type=kotlin.Int origin=null - $this: GET_VAR ': .C declared in .C' type=.C origin=null + $this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[.BaseClass; .I]' type=.C arg1: CONST Int type=kotlin.Int value=5 then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' CONST String type=kotlin.String value="5" @@ -205,7 +205,7 @@ FILE fqName: fileName:/useImportedMember.kt if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun (): kotlin.Int declared in .C' type=kotlin.Int origin=null - $this: GET_VAR ': .C declared in .C' type=.C origin=null + $this: CONST Int type=kotlin.Int value=5 arg1: CONST Int type=kotlin.Int value=6 then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' CONST String type=kotlin.String value="6" @@ -215,7 +215,7 @@ FILE fqName: fileName:/useImportedMember.kt $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun g1 (t: T of .C.g1): T of .C.g1 declared in .C' type=kotlin.String origin=null : kotlin.String - $this: GET_VAR ': .C declared in .C' type=.C origin=null + $this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[.BaseClass; .I]' type=.C t: CONST String type=kotlin.String value="7" arg1: CONST String type=kotlin.String value="7" then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' @@ -225,7 +225,7 @@ FILE fqName: fileName:/useImportedMember.kt if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun (): T of declared in .C' type=kotlin.String origin=null - $this: GET_VAR ': .C declared in .C' type=.C origin=null + $this: CONST String type=kotlin.String value="8" arg1: CONST String type=kotlin.String value="8" then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' CONST String type=kotlin.String value="8" @@ -235,7 +235,7 @@ FILE fqName: fileName:/useImportedMember.kt $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public open fun fromInterface (): T of .I.fromInterface declared in .I' type=kotlin.Int origin=null : kotlin.Int - $this: GET_VAR ': .I declared in .I' type=.I<*> origin=null + $this: CONST Int type=kotlin.Int value=9 arg1: CONST Int type=kotlin.Int value=9 then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' CONST String type=kotlin.String value="9" @@ -244,7 +244,7 @@ FILE fqName: fileName:/useImportedMember.kt if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public final fun (): T of declared in .BaseClass' type=kotlin.String origin=null - $this: GET_VAR ': .BaseClass declared in .BaseClass' type=.BaseClass origin=null + $this: CONST String type=kotlin.String value="10" arg1: CONST String type=kotlin.String value="10" then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' CONST String type=kotlin.String value="10" @@ -253,7 +253,6 @@ FILE fqName: fileName:/useImportedMember.kt if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: CALL 'public open fun genericFromSuper (g: kotlin.String): kotlin.String declared in .I' type=kotlin.String origin=null - $this: GET_VAR ': .I declared in .I' type=.I<*> origin=null g: CONST String type=kotlin.String value="11" arg1: CONST String type=kotlin.String value="11" then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in '