[NI] Initial support of "not enough information" diagnostic
#KT-30590 In Progress
This commit is contained in:
@@ -735,6 +735,8 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtParameter> CANNOT_INFER_PARAMETER_TYPE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_CANNOT_CAPTURE_TYPES = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
+2
@@ -831,6 +831,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, "Type inference failed: {0}", TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER);
|
||||
MAP.put(TYPE_INFERENCE_CANNOT_CAPTURE_TYPES, "Type inference failed: {0}", TYPE_INFERENCE_CANNOT_CAPTURE_TYPES_RENDERER);
|
||||
MAP.put(TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER, "Type inference failed: {0}", TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER_RENDERER);
|
||||
MAP.put(NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, "Not enough information to infer type variable {0}", STRING);
|
||||
|
||||
MAP.put(TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR, "Type inference failed: {0}", TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR_RENDERER);
|
||||
MAP.put(TYPE_INFERENCE_INCORPORATION_ERROR, "Type inference failed. Please try to specify type arguments explicitly.");
|
||||
MAP.put(TYPE_INFERENCE_ONLY_INPUT_TYPES, "Type inference failed. The value of the type parameter {0} should be mentioned in input types " +
|
||||
|
||||
+14
-1
@@ -32,7 +32,8 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
val constantExpressionEvaluator: ConstantExpressionEvaluator,
|
||||
val context: BasicCallResolutionContext,
|
||||
val psiKotlinCall: PSIKotlinCall,
|
||||
val dataFlowValueFactory: DataFlowValueFactory
|
||||
val dataFlowValueFactory: DataFlowValueFactory,
|
||||
val allDiagnostics: List<KotlinCallDiagnostic>
|
||||
) : DiagnosticReporter {
|
||||
private val trace = context.trace as TrackingBindingTrace
|
||||
private val tracingStrategy: TracingStrategy get() = psiKotlinCall.tracingStrategy
|
||||
@@ -245,6 +246,18 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
NotEnoughInformationForTypeParameter::class.java -> {
|
||||
val error = diagnostic as NotEnoughInformationForTypeParameter
|
||||
val call = error.resolvedAtom.atom?.safeAs<PSIKotlinCall>()?.psiCall ?: call
|
||||
val expression = call.calleeExpression ?: return
|
||||
val typeVariableName = when (val typeVariable = error.typeVariable) {
|
||||
is TypeVariableFromCallableDescriptor -> typeVariable.originalTypeParameter.name.asString()
|
||||
is TypeVariableForLambdaReturnType -> "return type of lambda"
|
||||
else -> error("Unsupported type variable: $typeVariable")
|
||||
}
|
||||
trace.report(NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER.on(expression, typeVariableName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-3
@@ -423,13 +423,21 @@ class KotlinToResolvedCallTransformer(
|
||||
) {
|
||||
val trackingTrace = TrackingBindingTrace(trace)
|
||||
val newContext = context.replaceBindingTrace(trackingTrace)
|
||||
val diagnosticReporter =
|
||||
DiagnosticReporterByTrackingStrategy(constantExpressionEvaluator, newContext, completedCallAtom.atom.psiKotlinCall, context.dataFlowValueFactory)
|
||||
|
||||
val diagnosticHolder = KotlinDiagnosticsHolder.SimpleHolder()
|
||||
additionalDiagnosticReporter.reportAdditionalDiagnostics(completedCallAtom, resultingDescriptor, diagnosticHolder, diagnostics)
|
||||
|
||||
for (diagnostic in diagnostics + diagnosticHolder.getDiagnostics()) {
|
||||
val allDiagnostics = diagnostics + diagnosticHolder.getDiagnostics()
|
||||
|
||||
val diagnosticReporter = DiagnosticReporterByTrackingStrategy(
|
||||
constantExpressionEvaluator,
|
||||
newContext,
|
||||
completedCallAtom.atom.psiKotlinCall,
|
||||
context.dataFlowValueFactory,
|
||||
allDiagnostics
|
||||
)
|
||||
|
||||
for (diagnostic in allDiagnostics) {
|
||||
trackingTrace.reported = false
|
||||
diagnostic.report(diagnosticReporter)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user