DiagnosticReporterByTrackingStrategy: replace TODO() with assertions/errors
#KT-55079 Fixed
This commit is contained in:
committed by
Space Team
parent
d4f81cf67f
commit
b6fdc2dbfc
@@ -26,7 +26,9 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.VarianceConflictDiagnosticData;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.InferenceErrorData;
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintPosition;
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability;
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.WrongResolutionToClassifier;
|
||||
import org.jetbrains.kotlin.resolve.calls.util.BuilderLambdaLabelingInfo;
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DescriptorBasedDeprecationInfo;
|
||||
@@ -62,6 +64,7 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory1<PsiElement, String> NEW_INFERENCE_ERROR = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> NEW_INFERENCE_DIAGNOSTIC = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory2<PsiElement, CandidateApplicability, String> NEW_INFERENCE_UNKNOWN_ERROR = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory0<KtElement> NON_APPLICABLE_CALL_FOR_BUILDER_INFERENCE = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<PsiElement, Pair<LanguageFeature, LanguageVersionSettings>> UNSUPPORTED_FEATURE = DiagnosticFactory1.create(ERROR);
|
||||
@@ -919,6 +922,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);
|
||||
DiagnosticFactory3<PsiElement, KotlinType, KotlinType, ConstraintPosition> TYPE_MISMATCH_IN_CONSTRAINT = DiagnosticFactory3.create(ERROR);
|
||||
|
||||
// Type inference
|
||||
|
||||
|
||||
+6
@@ -526,6 +526,11 @@ public class DefaultErrorMessages {
|
||||
"Constraint error in receiver type argument: inferred type is {1} but {0} was expected",
|
||||
RENDER_TYPE, RENDER_TYPE
|
||||
);
|
||||
MAP.put(
|
||||
TYPE_MISMATCH_IN_CONSTRAINT,
|
||||
"Type mismatch in constraint system: actual type is {1} but {0} was expected. Constraint position is {2}",
|
||||
RENDER_TYPE, RENDER_TYPE, TO_STRING
|
||||
);
|
||||
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");
|
||||
@@ -795,6 +800,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNSUPPORTED_WARNING, "Unsupported [{0}]. This warning will be an error in future releases", STRING);
|
||||
MAP.put(NEW_INFERENCE_ERROR, "New inference error [{0}]", STRING);
|
||||
MAP.put(NEW_INFERENCE_DIAGNOSTIC, "New inference [{0}]", STRING);
|
||||
MAP.put(NEW_INFERENCE_UNKNOWN_ERROR, "Unknown error in new inference with applicability ''{0}'' and target ''{1}'', please report to https://youtrack.jetbrains.com/newIssue?project=KT", TO_STRING, STRING);
|
||||
MAP.put(NON_APPLICABLE_CALL_FOR_BUILDER_INFERENCE, "Non-applicable call for builder inference");
|
||||
|
||||
MAP.put(UNSUPPORTED_FEATURE, "{0}", new LanguageFeatureMessageRenderer(LanguageFeatureMessageRenderer.Type.UNSUPPORTED));
|
||||
|
||||
+73
-6
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.StubTypeForBuilderInference
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
@@ -148,6 +149,17 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
val callElement = psiKotlinCall.psiCall.callElement
|
||||
trace.report(UNSUPPORTED_CONTEXTUAL_DECLARATION_CALL.on(callElement))
|
||||
}
|
||||
|
||||
is AdaptedCallableReferenceIsUsedWithReflection, is NotCallableMemberReference, is CallableReferencesDefaultArgumentUsed -> {
|
||||
// AdaptedCallableReferenceIsUsedWithReflection -> reported in onCallArgument
|
||||
// NotCallableMemberReference -> UNSUPPORTED reported in DoubleColonExpressionResolver
|
||||
// CallableReferencesDefaultArgumentUsed -> possible in 1.3 and earlier versions only
|
||||
return
|
||||
}
|
||||
|
||||
else -> {
|
||||
unknownError(diagnostic, "onCall")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +176,23 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
val expectedTypeArgumentsCount = diagnostic.descriptor.typeParameters.size
|
||||
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(reportElement, expectedTypeArgumentsCount, diagnostic.descriptor))
|
||||
}
|
||||
else -> {
|
||||
unknownError(diagnostic, "onTypeArguments")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun unknownError(diagnostic: KotlinCallDiagnostic, onTarget: String) {
|
||||
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
|
||||
throw AssertionError("$onTarget should not be called with ${diagnostic::class.java}")
|
||||
} else {
|
||||
trace.report(
|
||||
NEW_INFERENCE_UNKNOWN_ERROR.on(
|
||||
psiKotlinCall.psiCall.callElement,
|
||||
diagnostic.candidateApplicability,
|
||||
onTarget
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +235,9 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
)
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
unknownError(diagnostic, "onCallReceiver")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,6 +356,16 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
is NotCallableMemberReference, is NotCallableExpectedType -> {
|
||||
// NotCallableMemberReference -> UNSUPPORTED is reported in DoubleColonExpressionResolver
|
||||
// NotCallableExpectedType -> TYPE_MISMATCH is reported in reportConstraintErrorByPosition
|
||||
return
|
||||
}
|
||||
|
||||
else -> {
|
||||
unknownError(diagnostic, "onCallArgument")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,6 +390,9 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
)
|
||||
)
|
||||
is ArgumentPassedTwice -> trace.report(ARGUMENT_PASSED_TWICE.on(nameReference))
|
||||
else -> {
|
||||
unknownError(diagnostic, "onCallArgumentName")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,6 +414,9 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
unknownError(diagnostic, "onCallArgumentSpread")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +563,6 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
BuilderInferencePosition -> {
|
||||
// some error reported later?
|
||||
}
|
||||
is CallableReferenceConstraintPosition<*> -> TODO()
|
||||
is DeclaredUpperBoundConstraintPosition<*> -> {
|
||||
val originalCall = (position as DeclaredUpperBoundConstraintPositionImpl).kotlinCall
|
||||
val typeParameterDescriptor = position.typeParameter
|
||||
@@ -533,13 +580,27 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
is DelegatedPropertyConstraintPosition<*> -> {
|
||||
// DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, reported later
|
||||
}
|
||||
is IncorporationConstraintPosition -> TODO()
|
||||
is InjectedAnotherStubTypeConstraintPosition<*> -> TODO()
|
||||
is KnownTypeParameterConstraintPosition<*> -> {
|
||||
// UPPER_BOUND_VIOLATED, reported later?
|
||||
}
|
||||
is LHSArgumentConstraintPosition<*, *> -> TODO()
|
||||
SimpleConstraintSystemConstraintPosition -> TODO()
|
||||
is CallableReferenceConstraintPosition<*>,
|
||||
is IncorporationConstraintPosition,
|
||||
is InjectedAnotherStubTypeConstraintPosition<*>,
|
||||
is LHSArgumentConstraintPosition<*, *>,
|
||||
SimpleConstraintSystemConstraintPosition -> {
|
||||
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
|
||||
throw AssertionError("Constraint error in unexpected position: $position")
|
||||
} else {
|
||||
report(
|
||||
TYPE_MISMATCH_IN_CONSTRAINT.on(
|
||||
psiKotlinCall.psiCall.callElement,
|
||||
error.upperKotlinType,
|
||||
error.lowerKotlinType,
|
||||
position
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -716,10 +777,16 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
trace.reportDiagnosticOnce(diagnostic)
|
||||
}
|
||||
}
|
||||
// ConstrainingTypeIsError means that some type isError, so it's reported somewhere else
|
||||
is ConstrainingTypeIsError -> {}
|
||||
// LowerPriorityToPreserveCompatibility is not expected to report something
|
||||
is LowerPriorityToPreserveCompatibility -> {}
|
||||
// NoSuccessfulFork does not exist in K1
|
||||
is NoSuccessfulFork -> {}
|
||||
is NotEnoughInformationForTypeParameter<*> -> {}
|
||||
// NotEnoughInformationForTypeParameterImpl is already considered above
|
||||
is NotEnoughInformationForTypeParameter<*> -> {
|
||||
throw AssertionError("constraintError should not be called with ${error::class.java}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user