KT-61728 [LL API] Use ContextCollector in AllCandidatesResolver

Fix testdata for builder inference test in resolve tests - now it's the
same between K1 and K2
This commit is contained in:
Roman Golyshev
2023-09-06 11:15:34 +02:00
committed by Space Team
parent ce371df5f6
commit 23363ef1bd
3 changed files with 8 additions and 48 deletions
@@ -1,43 +0,0 @@
KtApplicableCallCandidateInfo:
candidate = KtSimpleFunctionCall:
isImplicitInvoke = false
partiallyAppliedSymbol = KtPartiallyAppliedSymbol:
dispatchReceiver = KtImplicitReceiverValue:
symbol = KtReceiverParameterSymbol:
annotationsList: []
origin: SOURCE
owningCallableSymbol: KtAnonymousFunctionSymbol(<local>/<no name provided>)
type: KtUsualClassType:
annotationsList: []
ownTypeArguments: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/String
]
type: test/Target<kotlin/String>
type = test.Target<kotlin.String>
extensionReceiver = null
signature = KtFunctionLikeSignature:
receiverType = null
returnType = kotlin.Unit
symbol = test/Target.add(<dispatch receiver>: test.Target<T>, t: T): kotlin.Unit
valueParameters = [
KtVariableLikeSignature:
name = t
receiverType = null
returnType = kotlin.String
symbol = t: T
callableIdIfNonLocal = null
]
callableIdIfNonLocal = test/Target.add
typeArgumentsMapping = {}
argumentMapping = {
s -> (KtVariableLikeSignature:
name = t
receiverType = null
returnType = kotlin.String
symbol = t: T
callableIdIfNonLocal = null)
}
isInBestCandidates = true
@@ -16,7 +16,7 @@ KtApplicableCallCandidateInfo:
type: kotlin/String
]
type: test/Target<kotlin/String>
type = test.Target<Stub (chain inference): TypeVariable(T)>
type = test.Target<kotlin.String>
extensionReceiver = null
signature = KtFunctionLikeSignature:
receiverType = null
@@ -26,7 +26,7 @@ KtApplicableCallCandidateInfo:
KtVariableLikeSignature:
name = t
receiverType = null
returnType = T
returnType = kotlin.String
symbol = t: T
callableIdIfNonLocal = null
]
@@ -36,7 +36,7 @@ KtApplicableCallCandidateInfo:
s -> (KtVariableLikeSignature:
name = t
receiverType = null
returnType = T
returnType = kotlin.String
symbol = t: T
callableIdIfNonLocal = null)
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.resolver
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LLFirResolveSession
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirFile
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.resolveToFirSymbol
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.ContextCollector
import org.jetbrains.kotlin.analysis.utils.printer.parentsOfType
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
@@ -16,6 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.calleeReference
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.SessionHolderImpl
import org.jetbrains.kotlin.fir.resolve.calls.InapplicableCandidate
import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext
import org.jetbrains.kotlin.fir.resolve.calls.tower.FirTowerResolver
@@ -95,8 +97,10 @@ class AllCandidatesResolver(private val firSession: FirSession) {
@OptIn(PrivateForInline::class, SymbolInternals::class)
private fun initializeBodyResolveContext(firResolveSession: LLFirResolveSession, element: KtElement) {
val firFile = element.containingKtFile.getOrBuildFirFile(firResolveSession)
// Set up needed context to get all candidates.
val towerContext = firResolveSession.getTowerContextProvider(element.containingKtFile).getClosestAvailableParentContext(element)
val towerContext = ContextCollector.process(firFile, bodyResolveComponents, element)?.towerDataContext
towerContext?.let { bodyResolveComponents.context.replaceTowerDataContext(it) }
val containingDeclarations =
element.parentsOfType<KtDeclaration>().map { it.resolveToFirSymbol(firResolveSession).fir }.toList().asReversed()
@@ -104,7 +108,6 @@ class AllCandidatesResolver(private val firSession: FirSession) {
// `towerContext` from above should already contain all the scopes for the file,
// so we just set it manually without calling `withFile`
val firFile = element.containingKtFile.getOrBuildFirFile(firResolveSession)
bodyResolveComponents.context.file = firFile
}