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:
committed by
Space Team
parent
2d755aabe7
commit
3fbb7bc920
+10
-3
@@ -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)
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
/Call.kt:(232,241): error: Cannot access class 'com.result.B'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/Call.kt:(253,262): error: Cannot access class 'com.result.B'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/Call.kt:(271,280): error: Cannot access class 'com.result.B'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/Call.kt:(294,296): error: Cannot access class 'com.result.B'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/Call.kt:(316,334): error: Cannot access class 'com.result.Owner.Nested'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/Call.kt:(316,334): error: Cannot access class 'com.result.Owner.Nested.VeryNested'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/Call.kt:(337,345): error: Cannot access class 'com.result.Owner.Nested'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/Call.kt:(346,355): error: Cannot access class 'com.result.Owner.Nested.VeryNested'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/Call.kt:(383,389): error: Unresolved reference 'result'.
|
||||
|
||||
+3
-3
@@ -81,9 +81,9 @@ import com.repo.request_withNested
|
||||
|
||||
class Model {
|
||||
fun call() {
|
||||
request_a().mapError <!MISSING_DEPENDENCY_CLASS!>{ 1 + 1 }<!>
|
||||
request_a().mapError { <!MISSING_DEPENDENCY_CLASS!>it<!> -> 1 + 1 }
|
||||
request_withNested().mapError <!MISSING_DEPENDENCY_CLASS!>{ 1 + 1 }<!>
|
||||
<!MISSING_DEPENDENCY_CLASS!>request_a<!>().mapError <!MISSING_DEPENDENCY_CLASS!>{ 1 + 1 }<!>
|
||||
<!MISSING_DEPENDENCY_CLASS!>request_a<!>().mapError { <!MISSING_DEPENDENCY_CLASS!>it<!> -> 1 + 1 }
|
||||
<!MISSING_DEPENDENCY_CLASS, MISSING_DEPENDENCY_CLASS!>request_withNested<!>().<!MISSING_DEPENDENCY_CLASS!>mapError<!> <!MISSING_DEPENDENCY_CLASS!>{ 1 + 1 }<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// -- Module: <missing> --
|
||||
|
||||
// -- Module: <library> --
|
||||
|
||||
// -- Module: <main> --
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
/module_main_BoxedInaccessibleGenericTypeUsedByDependencies.fir.kt:(84,112): error: Cannot access class 'InaccessibleType'. Check your module classpath for missing or conflicting dependencies.
|
||||
|
||||
/module_main_BoxedInaccessibleGenericTypeUsedByDependencies.fir.kt:(84,114): error: Argument type mismatch: actual type is 'Box<CapturedType(out ERROR CLASS: Inconsistent type: InaccessibleType<kotlin/Any?> (parameters.size = 0, arguments.size = 1))>', but 'Box<InaccessibleType<kotlin.Any?>>' was expected.
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||
// MODULE: missing
|
||||
|
||||
class InaccessibleType<ITTP>
|
||||
@@ -12,5 +13,5 @@ fun consumeBoxedInaccessibleType(arg: Box<InaccessibleType<Any?>>) {}
|
||||
// MODULE: main(library)
|
||||
|
||||
fun test() {
|
||||
consumeBoxedInaccessibleType(<!ARGUMENT_TYPE_MISMATCH("Box<InaccessibleType<kotlin.Any?>>; Box<CapturedType(out ERROR CLASS: Inconsistent type: InaccessibleType<kotlin/Any?> (parameters.size = 0, arguments.size = 1))>")!>produceBoxedInaccessibleType()<!>)
|
||||
consumeBoxedInaccessibleType(<!ARGUMENT_TYPE_MISMATCH!><!MISSING_DEPENDENCY_CLASS!>produceBoxedInaccessibleType<!>()<!>)
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
// RENDER_DIAGNOSTICS_FULL_TEXT
|
||||
// MODULE: missing
|
||||
|
||||
class InaccessibleType<ITTP>
|
||||
|
||||
Reference in New Issue
Block a user