[FIR] Add session parameter to all "element --> reference" utilities

`FirDeserializedEnumAccessExpression` requires session to build proper
  reference, so it's important to have it in all utilities, which may
  pass this element as input

^KT-64975
This commit is contained in:
Dmitriy Novozhilov
2024-01-17 16:56:31 +02:00
committed by Space Team
parent bd9cb2b7e0
commit 150ff1172e
34 changed files with 151 additions and 78 deletions
@@ -35,7 +35,8 @@ internal fun mapAnnotationParameters(annotation: FirAnnotation): Map<Name, FirEx
withClassEntry("annotationTypeRef", annotation.annotationTypeRef)
@OptIn(UnresolvedExpressionTypeAccess::class)
withClassEntry("coneTypeOrNull", annotation.coneTypeOrNull)
annotation.toReference()?.let { withClassEntry("calleeReference", it) }
@OptIn(UnsafeExpressionUtility::class)
annotation.toReferenceUnsafe()?.let { withClassEntry("calleeReference", it) }
}
return annotation.argumentMapping.mapping.mapKeys { (name, _) -> name }
@@ -220,7 +220,7 @@ internal class KtFirCallResolver(
return when (this) {
is FirResolvable, is FirVariableAssignment -> {
when (val calleeReference = toReference()) {
when (val calleeReference = toReference(analysisSession.useSiteSession)) {
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
@@ -794,7 +794,10 @@ internal class KtFirCallResolver(
@OptIn(SymbolInternals::class)
private fun getInitializerOfReferencedLocalVariable(variableReference: FirExpression): FirFunctionCall? {
return variableReference.toReference()?.toResolvedVariableSymbol()?.fir?.initializer as? FirFunctionCall
return variableReference.toReference(firResolveSession.useSiteFirSession)
?.toResolvedVariableSymbol()
?.fir
?.initializer as? FirFunctionCall
}
private fun getOperationPartiallyAppliedSymbolsForCompoundVariableAccess(
@@ -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.toReference() as? FirResolvedNamedReference)?.resolvedSymbol
val callee = (firCall.toReference(firResolveSession.useSiteFirSession) as? FirResolvedNamedReference)?.resolvedSymbol
if (callee?.fir?.origin == FirDeclarationOrigin.SamConstructor) {
val substitutor = (firCall as? FirQualifiedAccessExpression)
?.createConeSubstitutorFromTypeArguments(discardErrorTypes = true)
@@ -41,7 +41,6 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getCallNameExpression
import org.jetbrains.kotlin.psi.psiUtil.getPossiblyQualifiedCallExpression
import org.jetbrains.kotlin.psi.psiUtil.unwrapNullability
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.calls.util.getCalleeExpressionIfAny
import org.jetbrains.kotlin.util.OperatorNameConventions
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment