[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:
committed by
Space Team
parent
bd9cb2b7e0
commit
150ff1172e
@@ -114,7 +114,7 @@ class FirCallResolver(
|
||||
val resultFunctionCall = if (candidate != null && candidate.callInfo != result.info) {
|
||||
// This branch support case for the call of the type `a.invoke()`
|
||||
// 1. Handle candidate for `a`
|
||||
(resolvedReceiver?.toReference() as? FirNamedReferenceWithCandidate)?.candidate?.updateSourcesOfReceivers()
|
||||
(resolvedReceiver?.toReference(session) as? FirNamedReferenceWithCandidate)?.candidate?.updateSourcesOfReceivers()
|
||||
// 2. Handle candidate for `invoke`
|
||||
candidate.updateSourcesOfReceivers()
|
||||
functionCall.copyAsImplicitInvokeCall {
|
||||
|
||||
@@ -533,7 +533,7 @@ private fun getExpectedTypeWithImplicitIntegerCoercion(
|
||||
if (argument.isIntegerLiteralOrOperatorCall()) {
|
||||
argument.resolvedType
|
||||
} else {
|
||||
argument.toReference()?.toResolvedCallableSymbol()?.takeIf {
|
||||
argument.toReference(session)?.toResolvedCallableSymbol()?.takeIf {
|
||||
it.rawStatus.isConst && it.isMarkedWithImplicitIntegerCoercion
|
||||
}?.resolvedReturnType
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ object CheckDslScopeViolation : ResolutionStage() {
|
||||
|
||||
override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) {
|
||||
fun checkReceiver(receiver: FirExpression?) {
|
||||
val thisReference = receiver?.toReference() as? FirThisReference ?: return
|
||||
val thisReference = receiver?.toReference(context.session) as? FirThisReference ?: return
|
||||
if (thisReference.isImplicit) {
|
||||
checkImpl(
|
||||
candidate,
|
||||
@@ -755,7 +755,7 @@ internal object CheckHiddenDeclaration : ResolutionStage() {
|
||||
/** Actual declarations are checked by [FirDeprecationChecker] */
|
||||
if (symbol.isActual) return
|
||||
val deprecation = symbol.getDeprecation(context.session, callInfo.callSite)
|
||||
if (deprecation?.deprecationLevel == DeprecationLevelValue.HIDDEN || isHiddenForThisCallSite(symbol, callInfo, candidate)) {
|
||||
if (deprecation?.deprecationLevel == DeprecationLevelValue.HIDDEN || isHiddenForThisCallSite(symbol, callInfo, candidate, context.session)) {
|
||||
sink.yieldDiagnostic(HiddenCandidate)
|
||||
}
|
||||
}
|
||||
@@ -764,8 +764,9 @@ internal object CheckHiddenDeclaration : ResolutionStage() {
|
||||
symbol: FirCallableSymbol<*>,
|
||||
callInfo: CallInfo,
|
||||
candidate: Candidate,
|
||||
session: FirSession
|
||||
): Boolean {
|
||||
val isSuperCall = callInfo.callSite.isSuperCall()
|
||||
val isSuperCall = callInfo.callSite.isSuperCall(session)
|
||||
if (symbol.fir.dispatchReceiverType == null || symbol !is FirNamedFunctionSymbol) return false
|
||||
if (symbol.isHidden(isSuperCall)) return true
|
||||
|
||||
@@ -784,8 +785,8 @@ internal object CheckHiddenDeclaration : ResolutionStage() {
|
||||
return result
|
||||
}
|
||||
|
||||
private fun FirElement.isSuperCall(): Boolean =
|
||||
this is FirQualifiedAccessExpression && explicitReceiver?.toReference() is FirSuperReference
|
||||
private fun FirElement.isSuperCall(session: FirSession): Boolean =
|
||||
this is FirQualifiedAccessExpression && explicitReceiver?.toReference(session) is FirSuperReference
|
||||
|
||||
private fun FirCallableSymbol<*>.isHidden(isSuperCall: Boolean): Boolean {
|
||||
val fir = fir
|
||||
|
||||
@@ -166,7 +166,8 @@ private fun FirMemberDeclaration.getBackingFieldIfApplicable(): FirBackingField?
|
||||
private fun isExplicitReceiverExpression(receiverExpression: FirExpression?): Boolean {
|
||||
if (receiverExpression == null) return false
|
||||
// Only FirThisReference may be a reference in implicit receiver
|
||||
val thisReference = receiverExpression.toReference() as? FirThisReference ?: return true
|
||||
@OptIn(UnsafeExpressionUtility::class)
|
||||
val thisReference = receiverExpression.toReferenceUnsafe() as? FirThisReference ?: return true
|
||||
return !thisReference.isImplicit
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -306,7 +306,9 @@ private object WhenOnEnumExhaustivenessChecker : WhenExhaustivenessChecker() {
|
||||
override fun visitEqualityOperatorCall(equalityOperatorCall: FirEqualityOperatorCall, data: MutableSet<FirEnumEntry>) {
|
||||
if (!equalityOperatorCall.operation.let { it == FirOperation.EQ || it == FirOperation.IDENTITY }) return
|
||||
val argument = equalityOperatorCall.arguments[1]
|
||||
val symbol = argument.toResolvedCallableReference()?.resolvedSymbol as? FirVariableSymbol<*> ?: return
|
||||
|
||||
@OptIn(UnsafeExpressionUtility::class)
|
||||
val symbol = argument.toResolvedCallableReferenceUnsafe()?.resolvedSymbol as? FirVariableSymbol<*> ?: return
|
||||
val checkedEnumEntry = symbol.fir as? FirEnumEntry ?: return
|
||||
data.add(checkedEnumEntry)
|
||||
}
|
||||
@@ -360,7 +362,8 @@ private object WhenOnSealedClassExhaustivenessChecker : WhenExhaustivenessChecke
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
argument.toResolvedCallableSymbol()?.takeIf { it.fir is FirEnumEntry }
|
||||
@OptIn(UnsafeExpressionUtility::class)
|
||||
argument.toResolvedCallableSymbolUnsafe()?.takeIf { it.fir is FirEnumEntry }
|
||||
}
|
||||
} ?: return
|
||||
processBranch(symbol, isNegated, data)
|
||||
|
||||
+2
-2
@@ -591,7 +591,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
|
||||
val generator = GeneratorOfPlusAssignCalls(
|
||||
assignmentOperatorStatement,
|
||||
assignmentOperatorStatement.toReference()?.source,
|
||||
assignmentOperatorStatement.toReference(session)?.source,
|
||||
operation,
|
||||
leftArgument,
|
||||
rightArgument
|
||||
@@ -623,7 +623,7 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT
|
||||
// following `!!` is safe since `operatorIsSuccessful = true` implies `operatorCallReference != null`
|
||||
val operatorReturnTypeMatches = operatorIsSuccessful && operatorReturnTypeMatches(operatorCallReference!!.candidate)
|
||||
|
||||
val lhsReference = leftArgument.toReference()
|
||||
val lhsReference = leftArgument.toReference(session)
|
||||
val lhsSymbol = lhsReference?.toResolvedVariableSymbol()
|
||||
val lhsVariable = lhsSymbol?.fir
|
||||
val lhsIsVar = lhsVariable?.isVar == true
|
||||
|
||||
+1
-1
@@ -235,7 +235,7 @@ class ConeEffectExtractor(
|
||||
|
||||
private fun FirExpression.parseInvocationKind(): EventOccurrencesRange? {
|
||||
if (this !is FirQualifiedAccessExpression) return null
|
||||
val resolvedId = toResolvedCallableSymbol()?.callableId ?: return null
|
||||
val resolvedId = toResolvedCallableSymbol(session)?.callableId ?: return null
|
||||
return when (resolvedId) {
|
||||
FirContractsDslNames.EXACTLY_ONCE_KIND -> EventOccurrencesRange.EXACTLY_ONCE
|
||||
FirContractsDslNames.AT_LEAST_ONCE_KIND -> EventOccurrencesRange.AT_LEAST_ONCE
|
||||
|
||||
+1
-1
@@ -213,7 +213,7 @@ abstract class AbstractFirSpecificAnnotationResolveTransformer(
|
||||
|
||||
// If fully qualified, check that given package name matches the resolved one.
|
||||
val segments = generateSequence(receiver.explicitReceiver) { (it as? FirQualifiedAccessExpression)?.explicitReceiver }
|
||||
.mapNotNull { (it.toReference() as? FirSimpleNamedReference)?.name?.identifier }
|
||||
.mapNotNull { (it.toReference(session) as? FirSimpleNamedReference)?.name?.identifier }
|
||||
.toList()
|
||||
|
||||
if (segments.isNotEmpty() && FqName.fromSegments(segments.asReversed()) != symbol.classId.packageFqName) {
|
||||
|
||||
Reference in New Issue
Block a user