FIR checker: carry original candidate in ConeDiagnosticWithCandidates

This is needed by IDE when resolving calls because candidates carry more
information than just the targeting symbol.
This commit is contained in:
Tianyu Geng
2021-11-25 17:11:50 -08:00
committed by Ilya Kirillov
parent b2e1dfa6db
commit 58067e0a1e
9 changed files with 54 additions and 46 deletions
@@ -644,7 +644,7 @@ class FirCallResolver(
val candidate = candidates.singleOrNull()
val diagnostic = if (expectedCallKind == CallKind.Function) {
ConeFunctionCallExpectedError(name, candidates.any { isValueParametersNotEmpty(it) }, candidates.map { it.symbol })
ConeFunctionCallExpectedError(name, candidates.any { isValueParametersNotEmpty(it) }, candidates)
} else {
val singleExpectedCandidate = expectedCandidates?.singleOrNull()
@@ -654,7 +654,7 @@ class FirCallResolver(
}
if (fir is FirRegularClass) {
ConeResolutionToClassifierError(fir.symbol)
ConeResolutionToClassifierError(singleExpectedCandidate!!, fir.symbol)
} else {
val coneType = explicitReceiver?.typeRef?.coneType
when {
@@ -764,12 +764,12 @@ class FirCallResolver(
private fun createConeDiagnosticForCandidateWithError(
applicability: CandidateApplicability,
candidate: Candidate
): ConeDiagnosticWithCandidates {
): ConeDiagnostic {
return when (applicability) {
CandidateApplicability.HIDDEN -> ConeHiddenCandidateError(candidate.symbol)
CandidateApplicability.HIDDEN -> ConeHiddenCandidateError(candidate)
CandidateApplicability.VISIBILITY_ERROR -> ConeVisibilityError(candidate.symbol)
CandidateApplicability.INAPPLICABLE_WRONG_RECEIVER -> ConeInapplicableWrongReceiver(listOf(candidate.symbol))
CandidateApplicability.NO_COMPANION_OBJECT -> ConeNoCompanionObject(candidate.symbol as FirRegularClassSymbol)
CandidateApplicability.INAPPLICABLE_WRONG_RECEIVER -> ConeInapplicableWrongReceiver(listOf(candidate))
CandidateApplicability.NO_COMPANION_OBJECT -> ConeNoCompanionObject(candidate)
else -> ConeInapplicableCandidateError(applicability, candidate)
}
}
@@ -138,7 +138,7 @@ private fun buildReflectionType(
) to callableReferenceAdaptation
}
is FirVariable -> createKPropertyType(fir, receiverType, returnTypeRef, candidate) to null
else -> ConeClassErrorType(ConeUnsupportedCallableReferenceTarget(fir)) to null
else -> ConeClassErrorType(ConeUnsupportedCallableReferenceTarget(candidate)) to null
}
}
@@ -542,15 +542,15 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
}
fun reportAmbiguity(): FirStatement {
val operatorCallSymbol = operatorCallReference?.candidateSymbol
val assignmentCallSymbol = assignCallReference?.candidateSymbol
val operatorCallCandidate = operatorCallReference?.candidate
val assignmentCallCandidate = assignCallReference?.candidate
requireNotNull(operatorCallSymbol)
requireNotNull(assignmentCallSymbol)
requireNotNull(operatorCallCandidate)
requireNotNull(assignmentCallCandidate)
return buildErrorExpression {
source = assignmentOperatorStatement.source
diagnostic = ConeOperatorAmbiguityError(listOf(operatorCallSymbol, assignmentCallSymbol))
diagnostic = ConeOperatorAmbiguityError(listOf(operatorCallCandidate, assignmentCallCandidate))
}
}