[FIR] Refactor val FirElement.calleeReference utility

1. Convert it to `toReference()` function to make it consistent with other
   similar utilities
2. Provide the proper implementation

^KT-64975
This commit is contained in:
Dmitriy Novozhilov
2024-01-17 16:17:42 +02:00
committed by Space Team
parent 36958d585f
commit bd9cb2b7e0
21 changed files with 42 additions and 35 deletions
@@ -35,7 +35,7 @@ internal fun mapAnnotationParameters(annotation: FirAnnotation): Map<Name, FirEx
withClassEntry("annotationTypeRef", annotation.annotationTypeRef)
@OptIn(UnresolvedExpressionTypeAccess::class)
withClassEntry("coneTypeOrNull", annotation.coneTypeOrNull)
annotation.calleeReference?.let { withClassEntry("calleeReference", it) }
annotation.toReference()?.let { withClassEntry("calleeReference", it) }
}
return annotation.argumentMapping.mapping.mapKeys { (name, _) -> name }
@@ -202,4 +202,4 @@ internal fun hasAnnotation(
private fun FirBasedSymbol<*>.isFromCompilerRequiredAnnotationsPhase(classId: ClassId, session: FirSession): Boolean {
val requiredAnnotations = session.annotationPlatformSupport.requiredAnnotations
return fir.resolvePhase < FirResolvePhase.TYPES && classId in requiredAnnotations
}
}
@@ -220,7 +220,7 @@ internal class KtFirCallResolver(
return when (this) {
is FirResolvable, is FirVariableAssignment -> {
when (val calleeReference = calleeReference) {
when (val calleeReference = toReference()) {
is FirResolvedErrorReference -> transformErrorReference(this, calleeReference)
is FirResolvedNamedReference -> when (calleeReference.resolvedSymbol) {
// `calleeReference.resolvedSymbol` isn't guaranteed to be callable. For example, function type parameters used in
@@ -222,7 +222,7 @@ internal class KtFirExpressionTypeProvider(
val (ktCallElement, argumentExpression) = expression.getFunctionCallAsWithThisAsParameter() ?: return null
val firCall = ktCallElement.getOrBuildFir(firResolveSession)?.unwrapSafeCall() as? FirCall ?: return null
val callee = (firCall.calleeReference as? FirResolvedNamedReference)?.resolvedSymbol
val callee = (firCall.toReference() as? FirResolvedNamedReference)?.resolvedSymbol
if (callee?.fir?.origin == FirDeclarationOrigin.SamConstructor) {
val substitutor = (firCall as? FirQualifiedAccessExpression)
?.createConeSubstitutorFromTypeArguments(discardErrorTypes = true)