[FIR2IR] Provide object receivers for callable references
This commit is contained in:
+21
-9
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
@@ -78,12 +79,7 @@ internal class CallAndReferenceGenerator(
|
||||
)
|
||||
}
|
||||
}
|
||||
}.apply {
|
||||
applyTypeArguments(callableReferenceAccess)
|
||||
if (callableReferenceAccess.explicitReceiver !is FirResolvedQualifier) {
|
||||
applyReceivers(callableReferenceAccess)
|
||||
}
|
||||
}
|
||||
}.applyTypeArguments(callableReferenceAccess).applyReceivers(callableReferenceAccess)
|
||||
}
|
||||
|
||||
fun convertToIrCall(qualifiedAccess: FirQualifiedAccess, typeRef: FirTypeRef): IrExpression {
|
||||
@@ -237,9 +233,18 @@ internal class CallAndReferenceGenerator(
|
||||
}
|
||||
|
||||
fun convertToGetObject(qualifier: FirResolvedQualifier): IrExpression {
|
||||
val irType = qualifier.typeRef.toIrType()
|
||||
return convertToGetObject(qualifier, callableReferenceMode = false)!!
|
||||
}
|
||||
|
||||
private fun convertToGetObject(qualifier: FirResolvedQualifier, callableReferenceMode: Boolean): IrExpression? {
|
||||
val typeRef = qualifier.typeRef as? FirResolvedTypeRef
|
||||
val classSymbol = (typeRef?.type as? ConeClassLikeType)?.lookupTag?.toSymbol(session)
|
||||
if (callableReferenceMode && classSymbol is FirRegularClassSymbol) {
|
||||
if (classSymbol.classId != qualifier.classId) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
val irType = qualifier.typeRef.toIrType()
|
||||
return qualifier.convertWithOffsets { startOffset, endOffset ->
|
||||
if (classSymbol != null) {
|
||||
IrGetObjectValueImpl(
|
||||
@@ -331,9 +336,16 @@ internal class CallAndReferenceGenerator(
|
||||
|
||||
private fun FirQualifiedAccess.findIrReceiver(isDispatch: Boolean): IrExpression? {
|
||||
val firReceiver = if (isDispatch) dispatchReceiver else extensionReceiver
|
||||
if (firReceiver is FirResolvedQualifier) return convertToGetObject(firReceiver)
|
||||
if (firReceiver is FirResolvedQualifier) {
|
||||
return convertToGetObject(firReceiver, callableReferenceMode = this is FirCallableReferenceAccess)
|
||||
}
|
||||
return firReceiver.takeIf { it !is FirNoReceiverExpression }?.let { visitor.convertToIrExpression(it) }
|
||||
?: explicitReceiver?.let { visitor.convertToIrExpression(it) } // NB: this applies to the situation when call is unresolved
|
||||
?: explicitReceiver?.let {
|
||||
if (it is FirResolvedQualifier) {
|
||||
return convertToGetObject(it, callableReferenceMode = this is FirCallableReferenceAccess)
|
||||
}
|
||||
visitor.convertToIrExpression(it)
|
||||
}
|
||||
?: run {
|
||||
// Object case
|
||||
val callableReference = calleeReference as? FirResolvedNamedReference
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// !LANGUAGE: +JvmFieldInInterface
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
class A {
|
||||
companion object {
|
||||
fun ok() = "OK"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
object Singleton {
|
||||
fun ok() = "OK"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
Vendored
+1
-2
@@ -85,8 +85,7 @@ FILE fqName:test fileName:/boundInnerGenericConstructor.kt
|
||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [test/foo]>#' type=IrErrorType
|
||||
CONST String type=kotlin.String value="O"
|
||||
CONST String type=kotlin.String value="K"
|
||||
FUNCTION_REFERENCE 'public constructor <init> (a: T of test.Foo, b: P of test.Foo.Inner) [primary] declared in test.Foo.Inner' type=kotlin.reflect.KFunction2<T of test.Foo, kotlin.Any?, test.Foo.Inner<kotlin.Any?>> origin=null reflectionTarget=<same>
|
||||
$this: GET_VAR 'val z: test.Foo<kotlin.String> [val] declared in test.box' type=test.Foo<kotlin.String> origin=null
|
||||
ERROR_EXPR 'Cannot bind 1 type arguments to ??? call with 0 type parameters' type=kotlin.reflect.KFunction2<T of test.Foo, kotlin.Any?, test.Foo.Inner<kotlin.Any?>>
|
||||
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in test'
|
||||
CALL 'public final fun plus (other: kotlin.Any?): kotlin.String [operator] declared in kotlin' type=kotlin.String origin=PLUS
|
||||
$receiver: ERROR_CALL 'Unresolved reference: <Unresolved name: a>#' type=IrErrorType
|
||||
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
FILE fqName:test fileName:/importedFromObject.kt
|
||||
CLASS OBJECT name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:test.Foo
|
||||
CONSTRUCTOR visibility:private <> () returnType:test.Foo [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
PROPERTY name:a visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
CONST String type=kotlin.String value=""
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-a> visibility:public modality:FINAL <> ($this:test.Foo) returnType:kotlin.String
|
||||
correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:test.Foo
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-a> (): kotlin.String declared in test.Foo'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.String visibility:private [final]' type=kotlin.String origin=null
|
||||
receiver: GET_VAR '<this>: test.Foo declared in test.Foo.<get-a>' type=test.Foo origin=null
|
||||
FUN name:foo visibility:public modality:FINAL <> ($this:test.Foo) returnType:kotlin.String
|
||||
$this: VALUE_PARAMETER name:<this> type:test.Foo
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.String declared in test.Foo'
|
||||
CONST String type=kotlin.String value=""
|
||||
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:<this> 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:<this> 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:<this> type:kotlin.Any
|
||||
PROPERTY name:test1 visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test1 type:kotlin.reflect.KProperty0<kotlin.String> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
PROPERTY_REFERENCE 'public final a: kotlin.String [val]' field=null getter='public final fun <get-a> (): kotlin.String declared in test.Foo' setter=null type=kotlin.reflect.KProperty0<kotlin.String> origin=null
|
||||
$this: GET_OBJECT 'CLASS OBJECT name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]' type=test.Foo
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test1> visibility:public modality:FINAL <> () returnType:kotlin.reflect.KProperty0<kotlin.String>
|
||||
correspondingProperty: PROPERTY name:test1 visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test1> (): kotlin.reflect.KProperty0<kotlin.String> declared in test'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test1 type:kotlin.reflect.KProperty0<kotlin.String> visibility:private [final,static]' type=kotlin.reflect.KProperty0<kotlin.String> origin=null
|
||||
PROPERTY name:test1a visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test1a type:kotlin.reflect.KProperty0<kotlin.String> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
PROPERTY_REFERENCE 'public final a: kotlin.String [val]' field=null getter='public final fun <get-a> (): kotlin.String declared in test.Foo' setter=null type=kotlin.reflect.KProperty0<kotlin.String> origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test1a> visibility:public modality:FINAL <> () returnType:kotlin.reflect.KProperty0<kotlin.String>
|
||||
correspondingProperty: PROPERTY name:test1a visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test1a> (): kotlin.reflect.KProperty0<kotlin.String> declared in test'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test1a type:kotlin.reflect.KProperty0<kotlin.String> visibility:private [final,static]' type=kotlin.reflect.KProperty0<kotlin.String> origin=null
|
||||
PROPERTY name:test2 visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test2 type:kotlin.reflect.KFunction0<kotlin.String> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
FUNCTION_REFERENCE 'public final fun foo (): kotlin.String declared in test.Foo' type=kotlin.reflect.KFunction0<kotlin.String> origin=null reflectionTarget=<same>
|
||||
$this: GET_OBJECT 'CLASS OBJECT name:Foo modality:FINAL visibility:public superTypes:[kotlin.Any]' type=test.Foo
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test2> visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction0<kotlin.String>
|
||||
correspondingProperty: PROPERTY name:test2 visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test2> (): kotlin.reflect.KFunction0<kotlin.String> declared in test'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test2 type:kotlin.reflect.KFunction0<kotlin.String> visibility:private [final,static]' type=kotlin.reflect.KFunction0<kotlin.String> origin=null
|
||||
PROPERTY name:test2a visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:test2a type:kotlin.reflect.KFunction0<kotlin.String> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
FUNCTION_REFERENCE 'public final fun foo (): kotlin.String declared in test.Foo' type=kotlin.reflect.KFunction0<kotlin.String> origin=null reflectionTarget=<same>
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test2a> visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction0<kotlin.String>
|
||||
correspondingProperty: PROPERTY name:test2a visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-test2a> (): kotlin.reflect.KFunction0<kotlin.String> declared in test'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test2a type:kotlin.reflect.KFunction0<kotlin.String> visibility:private [final,static]' type=kotlin.reflect.KFunction0<kotlin.String> origin=null
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
package test
|
||||
|
||||
import test.Foo.a
|
||||
|
||||
+1
@@ -69,3 +69,4 @@ FILE fqName:<root> fileName:/unboundMemberReferenceWithAdaptedArguments.kt
|
||||
BLOCK_BODY
|
||||
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [/use2]>#' type=IrErrorType
|
||||
FUNCTION_REFERENCE 'public final fun foo (vararg xs: kotlin.Int): kotlin.Int declared in <root>.Obj' type=kotlin.reflect.KFunction1<kotlin.IntArray, kotlin.Int> origin=null reflectionTarget=<same>
|
||||
$this: GET_OBJECT 'CLASS OBJECT name:Obj modality:FINAL visibility:public superTypes:[<root>.A]' type=<root>.Obj
|
||||
|
||||
Reference in New Issue
Block a user