[NI] Split KotlinCallDiagnostics and inference errors to different hierarchies
This commit is contained in:
+27
-18
@@ -69,15 +69,6 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
val reportOn = (diagnostic as NonApplicableCallForBuilderInferenceDiagnostic).kotlinCall
|
||||
trace.reportDiagnosticOnce(Errors.NON_APPLICABLE_CALL_FOR_BUILDER_INFERENCE.on(reportOn.psiKotlinCall.psiCall.callElement))
|
||||
}
|
||||
OnlyInputTypesDiagnostic::class.java -> {
|
||||
val typeVariable = (diagnostic as OnlyInputTypesDiagnostic).typeVariable as? TypeVariableFromCallableDescriptor ?: return
|
||||
psiKotlinCall.psiCall.calleeExpression?.let {
|
||||
val factory = if (context.languageVersionSettings.supportsFeature(LanguageFeature.NonStrictOnlyInputTypesChecks))
|
||||
TYPE_INFERENCE_ONLY_INPUT_TYPES_WARNING
|
||||
else TYPE_INFERENCE_ONLY_INPUT_TYPES
|
||||
trace.report(factory.on(it, typeVariable.originalTypeParameter))
|
||||
}
|
||||
}
|
||||
CandidateChosenUsingOverloadResolutionByLambdaAnnotation::class.java -> {
|
||||
trace.report(CANDIDATE_CHOSEN_USING_OVERLOAD_RESOLUTION_BY_LAMBDA_ANNOTATION.on(psiKotlinCall.psiCall.callElement))
|
||||
}
|
||||
@@ -340,10 +331,10 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
)
|
||||
}
|
||||
|
||||
override fun constraintError(diagnostic: KotlinCallDiagnostic) {
|
||||
when (diagnostic.javaClass) {
|
||||
override fun constraintError(error: ConstraintSystemError) {
|
||||
when (error.javaClass) {
|
||||
NewConstraintError::class.java -> {
|
||||
val constraintError = diagnostic as NewConstraintError
|
||||
val constraintError = error as NewConstraintError
|
||||
val position = constraintError.position.from
|
||||
val argument =
|
||||
when (position) {
|
||||
@@ -414,7 +405,8 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
|
||||
(position as? FixVariableConstraintPositionImpl)?.let {
|
||||
val morePreciseDiagnosticExists = allDiagnostics.any { other ->
|
||||
other is NewConstraintError && other.position.from !is FixVariableConstraintPositionImpl
|
||||
val otherError = other.constraintSystemError ?: return@any false
|
||||
otherError is NewConstraintError && otherError.position.from !is FixVariableConstraintPositionImpl
|
||||
}
|
||||
if (morePreciseDiagnosticExists) return
|
||||
|
||||
@@ -432,7 +424,7 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
}
|
||||
|
||||
CapturedTypeFromSubtyping::class.java -> {
|
||||
val capturedError = diagnostic as CapturedTypeFromSubtyping
|
||||
val capturedError = error as CapturedTypeFromSubtyping
|
||||
val position = capturedError.position
|
||||
val argumentPosition =
|
||||
position.safeAs<ArgumentConstraintPositionImpl>()
|
||||
@@ -449,11 +441,18 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
}
|
||||
}
|
||||
|
||||
NotEnoughInformationForTypeParameter::class.java -> {
|
||||
val error = diagnostic as NotEnoughInformationForTypeParameterImpl
|
||||
NotEnoughInformationForTypeParameterImpl::class.java -> {
|
||||
val error = error as NotEnoughInformationForTypeParameterImpl
|
||||
if (allDiagnostics.any {
|
||||
(it is ConstrainingTypeIsError && it.typeVariable == error.typeVariable)
|
||||
|| it is NewConstraintError || it is WrongCountOfTypeArguments
|
||||
when (it) {
|
||||
is WrongCountOfTypeArguments -> true
|
||||
is KotlinConstraintSystemDiagnostic -> {
|
||||
val otherError = it.error
|
||||
(otherError is ConstrainingTypeIsError && otherError.typeVariable == error.typeVariable)
|
||||
|| otherError is NewConstraintError
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
) return
|
||||
|
||||
@@ -473,6 +472,16 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
}
|
||||
trace.reportDiagnosticOnce(NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER.on(expression, typeVariableName))
|
||||
}
|
||||
|
||||
OnlyInputTypesDiagnostic::class.java -> {
|
||||
val typeVariable = (error as OnlyInputTypesDiagnostic).typeVariable as? TypeVariableFromCallableDescriptor ?: return
|
||||
psiKotlinCall.psiCall.calleeExpression?.let {
|
||||
val factory = if (context.languageVersionSettings.supportsFeature(LanguageFeature.NonStrictOnlyInputTypesChecks))
|
||||
TYPE_INFERENCE_ONLY_INPUT_TYPES_WARNING
|
||||
else TYPE_INFERENCE_ONLY_INPUT_TYPES
|
||||
trace.report(factory.on(it, typeVariable.originalTypeParameter))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-9
@@ -60,7 +60,6 @@ class CoroutineInferenceSession(
|
||||
// Simple calls are calls which might not have gone through type inference, but may contain unsubstituted postponed variables inside their types.
|
||||
private val simpleCommonCalls = arrayListOf<KtExpression>()
|
||||
|
||||
private val diagnostics = arrayListOf<KotlinCallDiagnostic>()
|
||||
private var hasInapplicableCall = false
|
||||
|
||||
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean {
|
||||
@@ -276,20 +275,16 @@ class CoroutineInferenceSession(
|
||||
if (hasConstraints) effectivelyEmptyCommonSystem = false
|
||||
}
|
||||
|
||||
for (diagnostic in diagnostics) {
|
||||
commonSystem.addError(diagnostic)
|
||||
}
|
||||
|
||||
return commonSystem to effectivelyEmptyCommonSystem
|
||||
}
|
||||
|
||||
private fun reportDiagnostics(completedCall: CallInfo, resolvedCall: ResolvedCall<*>, diagnostics: List<KotlinCallDiagnostic>) {
|
||||
private fun reportErrors(completedCall: CallInfo, resolvedCall: ResolvedCall<*>, errors: List<ConstraintSystemError>) {
|
||||
kotlinToResolvedCallTransformer.reportCallDiagnostic(
|
||||
completedCall.context,
|
||||
trace,
|
||||
completedCall.callResolutionResult.resultCallAtom,
|
||||
resolvedCall.resultingDescriptor,
|
||||
diagnostics
|
||||
errors.asDiagnostics()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -304,12 +299,12 @@ class CoroutineInferenceSession(
|
||||
|
||||
for (completedCall in commonCalls) {
|
||||
updateCall(completedCall, nonFixedTypesToResultSubstitutor, nonFixedTypesToResult)
|
||||
reportDiagnostics(completedCall, completedCall.resolvedCall, commonSystem.diagnostics)
|
||||
reportErrors(completedCall, completedCall.resolvedCall, commonSystem.diagnostics)
|
||||
}
|
||||
|
||||
for (callInfo in partiallyResolvedCallsInfo) {
|
||||
val resolvedCall = completeCall(callInfo, atomCompleter) ?: continue
|
||||
reportDiagnostics(callInfo, resolvedCall, commonSystem.diagnostics)
|
||||
reportErrors(callInfo, resolvedCall, commonSystem.diagnostics)
|
||||
}
|
||||
|
||||
for (simpleCall in simpleCommonCalls) {
|
||||
|
||||
+4
-4
@@ -904,10 +904,10 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
||||
}
|
||||
|
||||
diagnostics.forEach {
|
||||
val position = when (it) {
|
||||
is NewConstraintError -> it.position.originalPosition()
|
||||
is CapturedTypeFromSubtyping -> it.position.originalPosition()
|
||||
is ConstrainingTypeIsError -> it.position.originalPosition()
|
||||
val position = when (val error = it.constraintSystemError) {
|
||||
is NewConstraintError -> error.position.originalPosition()
|
||||
is CapturedTypeFromSubtyping -> error.position.originalPosition()
|
||||
is ConstrainingTypeIsError -> error.position.originalPosition()
|
||||
else -> null
|
||||
} as? ArgumentConstraintPositionImpl ?: return@forEach
|
||||
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
|
||||
diagnosticsHolder: KotlinDiagnosticsHolder.SimpleHolder,
|
||||
commonSystem: NewConstraintSystem
|
||||
): CallResolutionResult {
|
||||
val diagnostics = diagnosticsHolder.getDiagnostics() + callResolutionResult.diagnostics + commonSystem.diagnostics
|
||||
val diagnostics = diagnosticsHolder.getDiagnostics() + callResolutionResult.diagnostics + commonSystem.diagnostics.asDiagnostics()
|
||||
return CompletedCallResolutionResult(callResolutionResult.resultCallAtom, diagnostics, commonSystem.asReadOnlyStorage())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ class PSICallResolver(
|
||||
): ManyCandidates<D> {
|
||||
val resolvedCalls = diagnostic.candidates.map {
|
||||
kotlinToResolvedCallTransformer.onlyTransform<D>(
|
||||
it.resolvedCall, it.diagnosticsFromResolutionParts + it.getSystem().diagnostics
|
||||
it.resolvedCall, it.diagnosticsFromResolutionParts + it.getSystem().diagnostics.asDiagnostics()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user