[FIR] Apply type arguments for callable references
This commit is contained in:
+11
-13
@@ -52,26 +52,19 @@ internal class CallAndReferenceGenerator(
|
||||
when (symbol) {
|
||||
is IrPropertySymbol -> {
|
||||
IrPropertyReferenceImpl(
|
||||
startOffset, endOffset, type, symbol, 0,
|
||||
startOffset, endOffset, type, symbol,
|
||||
typeArgumentsCount = symbol.owner.getter?.typeParameters?.size ?: 0,
|
||||
symbol.owner.backingField?.symbol,
|
||||
symbol.owner.getter?.symbol,
|
||||
symbol.owner.setter?.symbol
|
||||
).apply {
|
||||
if (callableReferenceAccess.explicitReceiver !is FirResolvedQualifier) {
|
||||
applyReceivers(callableReferenceAccess)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
is IrFunctionSymbol -> {
|
||||
IrFunctionReferenceImpl(
|
||||
startOffset, endOffset, type, symbol,
|
||||
typeArgumentsCount = 0,
|
||||
typeArgumentsCount = symbol.owner.typeParameters.size,
|
||||
reflectionTarget = symbol
|
||||
).apply {
|
||||
if (callableReferenceAccess.explicitReceiver !is FirResolvedQualifier) {
|
||||
applyReceivers(callableReferenceAccess)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
IrErrorCallExpressionImpl(
|
||||
@@ -79,6 +72,11 @@ internal class CallAndReferenceGenerator(
|
||||
)
|
||||
}
|
||||
}
|
||||
}.apply {
|
||||
applyTypeArguments(callableReferenceAccess)
|
||||
if (callableReferenceAccess.explicitReceiver !is FirResolvedQualifier) {
|
||||
applyReceivers(callableReferenceAccess)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +298,7 @@ internal class CallAndReferenceGenerator(
|
||||
|
||||
private fun IrExpression.applyTypeArguments(access: FirQualifiedAccess): IrExpression {
|
||||
return when (this) {
|
||||
is IrCallWithIndexedArgumentsBase -> {
|
||||
is IrMemberAccessExpressionBase -> {
|
||||
val argumentsCount = access.typeArguments.size
|
||||
if (argumentsCount <= typeArgumentsCount) {
|
||||
apply {
|
||||
|
||||
+3
@@ -106,6 +106,8 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
): CompositeTransformResult<FirStatement> {
|
||||
val calleeReference =
|
||||
callableReferenceAccess.calleeReference as? FirNamedReferenceWithCandidate ?: return callableReferenceAccess.compose()
|
||||
val subCandidate = calleeReference.candidate
|
||||
val typeArguments = computeTypeArguments(callableReferenceAccess, subCandidate)
|
||||
|
||||
val typeRef = callableReferenceAccess.typeRef as FirResolvedTypeRef
|
||||
|
||||
@@ -114,6 +116,7 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
|
||||
val resultType = typeRef.withReplacedConeType(finalType)
|
||||
callableReferenceAccess.replaceTypeRef(resultType)
|
||||
callableReferenceAccess.replaceTypeArguments(typeArguments)
|
||||
|
||||
return callableReferenceAccess.transformCalleeReference(
|
||||
StoreCalleeReference,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
inline fun <TT> id(x: TT): TT = x
|
||||
inline fun <TT> String.extId(x: TT): String = this
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// KT-12630 KotlinReflectionInternalError on referencing some functions from stdlib
|
||||
|
||||
|
||||
+3
@@ -35,6 +35,7 @@ FILE fqName:<root> fileName:/typeArguments.kt
|
||||
FIELD PROPERTY_BACKING_FIELD name:test1 type:kotlin.Function1<kotlin.Int, kotlin.Unit> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
FUNCTION_REFERENCE 'public final fun topLevel1 <T> (x: T of <root>.topLevel1): kotlin.Unit [inline] declared in <root>' type=kotlin.reflect.KFunction1<kotlin.Int, kotlin.Unit> origin=null reflectionTarget=<same>
|
||||
<T>: kotlin.Int
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test1> visibility:public modality:FINAL <> () returnType:kotlin.Function1<kotlin.Int, kotlin.Unit>
|
||||
correspondingProperty: PROPERTY name:test1 visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
@@ -44,6 +45,7 @@ FILE fqName:<root> fileName:/typeArguments.kt
|
||||
FIELD PROPERTY_BACKING_FIELD name:test2 type:kotlin.Function1<kotlin.collections.List<kotlin.String>, kotlin.Unit> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
FUNCTION_REFERENCE 'public final fun topLevel2 <T> (x: kotlin.collections.List<T of <root>.topLevel2>): kotlin.Unit [inline] declared in <root>' type=kotlin.reflect.KFunction1<kotlin.collections.List<kotlin.String>, kotlin.Unit> origin=null reflectionTarget=<same>
|
||||
<T>: kotlin.String
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test2> visibility:public modality:FINAL <> () returnType:kotlin.Function1<kotlin.collections.List<kotlin.String>, kotlin.Unit>
|
||||
correspondingProperty: PROPERTY name:test2 visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
@@ -53,6 +55,7 @@ FILE fqName:<root> fileName:/typeArguments.kt
|
||||
FIELD PROPERTY_BACKING_FIELD name:test3 type:kotlin.Function1<kotlin.Int, kotlin.Unit> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
FUNCTION_REFERENCE 'public final fun objectMember <T> (x: T of <root>.Host.objectMember): kotlin.Unit [inline] declared in <root>.Host' type=kotlin.reflect.KFunction1<kotlin.Int, kotlin.Unit> origin=null reflectionTarget=<same>
|
||||
<T>: kotlin.Int
|
||||
$this: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Host
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test3> visibility:public modality:FINAL <> () returnType:kotlin.Function1<kotlin.Int, kotlin.Unit>
|
||||
correspondingProperty: PROPERTY name:test3 visibility:public modality:FINAL [val]
|
||||
|
||||
@@ -79,6 +79,7 @@ FILE fqName:<root> fileName:/genericPropertyRef.kt
|
||||
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalText$delegate type:<root>.DVal visibility:private [final,static]' type=<root>.DVal origin=GET_PROPERTY
|
||||
t: ERROR_CALL 'Unresolved reference: this@R|/additionalText|' type=<root>.Value<T of <root>.<get-additionalText>>
|
||||
p: PROPERTY_REFERENCE 'public final additionalText: kotlin.Int [delegated,val]' field='FIELD PROPERTY_DELEGATE name:additionalText$delegate type:<root>.DVal visibility:private [final,static]' getter='public final fun <get-additionalText> <T> (): kotlin.Int declared in <root>' setter=null type=kotlin.reflect.KProperty<*> origin=null
|
||||
<1>: <none>
|
||||
PROPERTY name:additionalValue visibility:public modality:FINAL [delegated,val]
|
||||
FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:<root>.DVal visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
@@ -94,6 +95,7 @@ FILE fqName:<root> fileName:/genericPropertyRef.kt
|
||||
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:<root>.DVal visibility:private [final,static]' type=<root>.DVal origin=GET_PROPERTY
|
||||
t: ERROR_CALL 'Unresolved reference: this@R|/additionalValue|' type=<root>.Value<T of <root>.<get-additionalValue>>
|
||||
p: PROPERTY_REFERENCE 'public final additionalValue: kotlin.Int [delegated,val]' field='FIELD PROPERTY_DELEGATE name:additionalValue$delegate type:<root>.DVal visibility:private [final,static]' getter='public final fun <get-additionalValue> <T> (): kotlin.Int declared in <root>' setter=null type=kotlin.reflect.KProperty<*> origin=null
|
||||
<1>: <none>
|
||||
CLASS CLASS name:DVal modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.DVal
|
||||
CONSTRUCTOR visibility:public <> (kmember:kotlin.Any) returnType:<root>.DVal [primary]
|
||||
@@ -184,6 +186,7 @@ FILE fqName:<root> fileName:/genericPropertyRef.kt
|
||||
FIELD PROPERTY_BACKING_FIELD name:barRef type:kotlin.reflect.KMutableProperty1<kotlin.String?, kotlin.String?> visibility:private [final,static]
|
||||
EXPRESSION_BODY
|
||||
PROPERTY_REFERENCE 'public final bar: T of <root>.<get-bar> [var]' field=null getter='public final fun <get-bar> <T> (): T of <root>.<get-bar> declared in <root>' setter='public final fun <set-bar> <T> (value: T of <root>.<get-bar>): kotlin.Unit declared in <root>' type=kotlin.reflect.KMutableProperty1<kotlin.String?, kotlin.String?> origin=null
|
||||
<1>: kotlin.String?
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-barRef> visibility:public modality:FINAL <> () returnType:kotlin.reflect.KMutableProperty1<kotlin.String?, kotlin.String?>
|
||||
correspondingProperty: PROPERTY name:barRef visibility:public modality:FINAL [val]
|
||||
BLOCK_BODY
|
||||
|
||||
@@ -320,3 +320,4 @@ FILE fqName:<root> fileName:/genericDelegatedDeepProperty.kt
|
||||
$this: GET_FIELD 'FIELD PROPERTY_DELEGATE name:additionalText$delegate type:<root>.additionalText$delegate.<no name provided> visibility:private [final,static]' type=<root>.additionalText$delegate.<no name provided> origin=GET_PROPERTY
|
||||
t: ERROR_CALL 'Unresolved reference: this@R|/additionalText|' type=<root>.Value<T of <root>.<get-additionalText>, <root>.CR<T of <root>.<get-additionalText>>>
|
||||
p: PROPERTY_REFERENCE 'public final additionalText: <root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>> [delegated,val]' field='FIELD PROPERTY_DELEGATE name:additionalText$delegate type:<root>.additionalText$delegate.<no name provided> visibility:private [final,static]' getter='public final fun <get-additionalText> <T> (): <root>.P<T of <root>.<get-additionalText>, T of <root>.<get-additionalText>> declared in <root>' setter=null type=kotlin.reflect.KProperty<*> origin=null
|
||||
<1>: <none>
|
||||
|
||||
@@ -64,6 +64,7 @@ FILE fqName:<root> fileName:/genericPropertyReferenceType.kt
|
||||
BLOCK_BODY
|
||||
CALL 'public final fun use (p: kotlin.reflect.KMutableProperty<kotlin.String>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
p: PROPERTY_REFERENCE 'public final y: T of <root>.<get-y> [var]' field=null getter='public final fun <get-y> <T> (): T of <root>.<get-y> declared in <root>' setter='public final fun <set-y> <T> (v: T of <root>.<get-y>): kotlin.Unit declared in <root>' type=kotlin.reflect.KMutableProperty0<kotlin.String> origin=null
|
||||
<1>: kotlin.String
|
||||
$receiver: CONSTRUCTOR_CALL 'public constructor <init> (x: T of <root>.C) [primary] declared in <root>.C' type=<root>.C<kotlin.String> origin=null
|
||||
<class: T>: kotlin.String
|
||||
x: CONST String type=kotlin.String value="abc"
|
||||
@@ -74,5 +75,6 @@ FILE fqName:<root> fileName:/genericPropertyReferenceType.kt
|
||||
GET_VAR 'a: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
|
||||
CALL 'public final fun use (p: kotlin.reflect.KMutableProperty<kotlin.String>): kotlin.Unit declared in <root>' type=kotlin.Unit origin=null
|
||||
p: PROPERTY_REFERENCE 'public final y: T of <root>.<get-y> [var]' field=null getter='public final fun <get-y> <T> (): T of <root>.<get-y> declared in <root>' setter='public final fun <set-y> <T> (v: T of <root>.<get-y>): kotlin.Unit declared in <root>' type=kotlin.reflect.KMutableProperty0<kotlin.String> origin=null
|
||||
<1>: kotlin.String
|
||||
$receiver: TYPE_OP type=<root>.C<kotlin.String> origin=IMPLICIT_CAST typeOperand=<root>.C<kotlin.String>
|
||||
GET_VAR 'a: kotlin.Any declared in <root>.test2' type=kotlin.Any origin=null
|
||||
|
||||
Reference in New Issue
Block a user