K1: report swallowed diagnostic about receiver type mismatch

#KT-55056 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-02-14 16:27:25 +01:00
committed by Space Team
parent 176325eaa7
commit bd27ec840c
21 changed files with 173 additions and 19 deletions
@@ -915,6 +915,7 @@ public interface Errors {
DiagnosticFactory2<PsiElement, KotlinType, KotlinType> TYPE_MISMATCH_WARNING_FOR_INCORRECT_CAPTURE_APPROXIMATION = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<PsiElement, KotlinType, KotlinType> RECEIVER_TYPE_MISMATCH_WARNING_FOR_INCORRECT_CAPTURE_APPROXIMATION = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<PsiElement, KotlinType, KotlinType> RECEIVER_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
// Type inference
@@ -519,6 +519,11 @@ public class DefaultErrorMessages {
"Extension receiver type mismatch: inferred type is {1} but {0} was expected. This warning will be an error soon. See https://youtrack.jetbrains.com/issue/KT-49404 for details",
RENDER_TYPE, RENDER_TYPE
);
MAP.put(
RECEIVER_TYPE_MISMATCH,
"Constraint error in receiver type argument: inferred type is {1} but {0} was expected",
RENDER_TYPE, RENDER_TYPE
);
MAP.put(LOCAL_EXTENSION_PROPERTY, "Local extension properties are not allowed");
MAP.put(LOCAL_VARIABLE_WITH_GETTER, "Local variables are not allowed to have getters");
MAP.put(LOCAL_VARIABLE_WITH_SETTER, "Local variables are not allowed to have setters");
@@ -459,19 +459,22 @@ class DiagnosticReporterByTrackingStrategy(
is ArgumentConstraintPosition<*> -> {
reportArgumentConstraintErrorByPosition(
error, position.argument as KotlinCallArgument,
isWarning, typeMismatchDiagnostic, report
isWarning, typeMismatchDiagnostic,
kotlinCall = null, report
)
}
is ReceiverConstraintPosition<*> -> {
reportArgumentConstraintErrorByPosition(
error, position.argument as KotlinCallArgument,
isWarning, typeMismatchDiagnostic, report
isWarning, typeMismatchDiagnostic,
kotlinCall = (position as ReceiverConstraintPositionImpl).kotlinCall, report
)
}
is LambdaArgumentConstraintPosition<*> -> {
reportArgumentConstraintErrorByPosition(
error, (position.lambda as ResolvedLambdaAtom).atom,
isWarning, typeMismatchDiagnostic, report
isWarning, typeMismatchDiagnostic,
kotlinCall = null, report
)
}
is BuilderInferenceExpectedTypeConstraintPosition -> {
@@ -545,6 +548,7 @@ class DiagnosticReporterByTrackingStrategy(
argument: KotlinCallArgument,
isWarning: Boolean,
typeMismatchDiagnostic: DiagnosticFactory2<KtExpression, KotlinType, KotlinType>,
kotlinCall: KotlinCall?,
report: (Diagnostic) -> Unit
) {
if (argument is LambdaKotlinCallArgument) {
@@ -562,8 +566,15 @@ class DiagnosticReporterByTrackingStrategy(
}
}
// TODO: FIXME (KT-55056)
val expression = argument.psiExpression ?: return
val expression = argument.psiExpression ?: run {
val psiCall = (kotlinCall as? PSIKotlinCall)?.psiCall ?: psiKotlinCall.psiCall
report(
RECEIVER_TYPE_MISMATCH.on(
psiCall.calleeExpression ?: psiCall.callElement, error.upperKotlinType, error.lowerKotlinType
)
)
return
}
val deparenthesized = KtPsiUtil.safeDeparenthesize(expression)
if (reportConstantTypeMismatch(error, deparenthesized)) return