K2: report MISSING_DEPENDENCY_CLASS in case of error type of expression

This commit is intended to get a more clear diagnostic in case when
the type checker creates an inconsistent error type due to some
classifier inaccessibility. Before this commit, we reported simply
ARGUMENT_TYPE_MISMATCH (see test). Now we report also
MISSING_DEPENDENCY_CLASS by analyzing an error type of a qualified
expression.

#KT-66356 Fixed
This commit is contained in:
Mikhail Glukhikh
2024-03-18 12:19:55 +01:00
committed by Space Team
parent 2d755aabe7
commit 3fbb7bc920
7 changed files with 34 additions and 7 deletions
@@ -27,12 +27,19 @@ import org.jetbrains.kotlin.fir.types.*
object FirMissingDependencyClassChecker : FirQualifiedAccessExpressionChecker(MppCheckerKind.Common), FirMissingDependencyClassProxy {
override fun check(expression: FirQualifiedAccessExpression, context: CheckerContext, reporter: DiagnosticReporter) {
val calleeReference = expression.calleeReference
val missingTypes = mutableSetOf<ConeKotlinType>()
if (!calleeReference.isError()) {
expression.resolvedType.forEachType {
if (it is ConeErrorType) {
considerType(it, missingTypes, context)
}
}
}
// To replicate K1 behavior, MISSING_DEPENDENCY_CLASS errors should still be reported on error references with a single candidate.
// All other callee errors should skip reporting of MISSING_DEPENDENCY_CLASS.
if (calleeReference.isError() && calleeReference.diagnostic !is ConeDiagnosticWithSingleCandidate) return
val missingTypes = mutableSetOf<ConeKotlinType>()
if (calleeReference.isError() && calleeReference.diagnostic !is ConeDiagnosticWithSingleCandidate && missingTypes.isEmpty()) return
val symbol = calleeReference.toResolvedCallableSymbol() ?: return
considerType(symbol.resolvedReturnTypeRef.coneType, missingTypes, context)