FIR2IR: temporarily allow null receivers & use findIr*Receiver also for fields

This commit is contained in:
Mikhail Glukhikh
2019-12-27 13:24:34 +03:00
parent 338281e05f
commit e4b2c238c7
4 changed files with 25 additions and 22 deletions
@@ -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
}
@@ -69,6 +69,7 @@ FILE fqName:<root> fileName:/memberExtension.kt
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 [operator] 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: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.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:<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]
@@ -49,6 +49,7 @@ FILE fqName:<root> 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=<root>.Z
value: CONST Int type=kotlin.Int value=1
CALL 'public final fun foo (): kotlin.Unit declared in <root>.Z' type=kotlin.Unit origin=null
$this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Z
@@ -61,6 +62,7 @@ FILE fqName:<root> fileName:/objectReference.kt
$this: VALUE_PARAMETER name:<this> type:<root>.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=<root>.Z
value: CONST Int type=kotlin.Int value=1
CALL 'public final fun foo (): kotlin.Unit declared in <root>.Z' type=kotlin.Unit origin=null
$this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Z
@@ -155,7 +155,7 @@ FILE fqName:<root> 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 <root>.C' type=kotlin.Int origin=null
$this: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.C origin=null
$this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[<root>.BaseClass; <root>.I<kotlin.String>]' type=<root>.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 <root>'
@@ -165,7 +165,7 @@ FILE fqName:<root> 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 <root>.C' type=kotlin.Int origin=null
$this: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.C origin=null
$this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[<root>.BaseClass; <root>.I<kotlin.String>]' type=<root>.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 <root>'
@@ -175,7 +175,7 @@ FILE fqName:<root> 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 <root>.C' type=kotlin.Int origin=null
$this: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.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 <root>'
CONST String type=kotlin.String value="3"
@@ -184,19 +184,19 @@ FILE fqName:<root> 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 <get-p> (): kotlin.Int declared in <root>.C' type=kotlin.Int origin=null
$this: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.C origin=null
$this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[<root>.BaseClass; <root>.I<kotlin.String>]' type=<root>.C
arg1: CONST Int type=kotlin.Int value=4
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
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 '<this>: <root>.C declared in <root>.C' type=<root>.C origin=null
receiver: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[<root>.BaseClass; <root>.I<kotlin.String>]' type=<root>.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 <get-p> (): kotlin.Int declared in <root>.C' type=kotlin.Int origin=null
$this: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.C origin=null
$this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[<root>.BaseClass; <root>.I<kotlin.String>]' type=<root>.C
arg1: CONST Int type=kotlin.Int value=5
then: RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
CONST String type=kotlin.String value="5"
@@ -205,7 +205,7 @@ FILE fqName:<root> 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 <get-ext> (): kotlin.Int declared in <root>.C' type=kotlin.Int origin=null
$this: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.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 <root>'
CONST String type=kotlin.String value="6"
@@ -215,7 +215,7 @@ FILE fqName:<root> 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: T of <root>.C.g1): T of <root>.C.g1 declared in <root>.C' type=kotlin.String origin=null
<T>: kotlin.String
$this: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.C origin=null
$this: GET_OBJECT 'CLASS OBJECT name:C modality:FINAL visibility:public superTypes:[<root>.BaseClass; <root>.I<kotlin.String>]' type=<root>.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 <root>'
@@ -225,7 +225,7 @@ FILE fqName:<root> 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 <get-g2> (): T of <uninitialized parent> declared in <root>.C' type=kotlin.String origin=null
$this: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.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 <root>'
CONST String type=kotlin.String value="8"
@@ -235,7 +235,7 @@ FILE fqName:<root> 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> (): T of <root>.I.fromInterface declared in <root>.I' type=kotlin.Int origin=null
<T>: kotlin.Int
$this: GET_VAR '<this>: <root>.I declared in <root>.I' type=<root>.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 <root>'
CONST String type=kotlin.String value="9"
@@ -244,7 +244,7 @@ FILE fqName:<root> 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 <get-fromClass> (): T of <uninitialized parent> declared in <root>.BaseClass' type=kotlin.String origin=null
$this: GET_VAR '<this>: <root>.BaseClass declared in <root>.BaseClass' type=<root>.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 <root>'
CONST String type=kotlin.String value="10"
@@ -253,7 +253,6 @@ FILE fqName:<root> 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 <root>.I' type=kotlin.String origin=null
$this: GET_VAR '<this>: <root>.I declared in <root>.I' type=<root>.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 <root>'