[NI] Support INAPPLICABLE_WRONG_RECEIVER candidate applicability

It is important for provideDelegate resolution, because if scope has
provideDelegate with wrong receiver we shouldn't resolve to it and
report any errors.
This commit is contained in:
Stanislav Erokhin
2017-06-08 19:16:33 +03:00
committed by Mikhail Zarechenskiy
parent e4b73fcdbd
commit 5f2cc75718
6 changed files with 32 additions and 16 deletions
@@ -151,8 +151,10 @@ class DiagnosticReporterByTrackingStrategy(
NewConstraintError::class.java -> {
val constraintError = diagnostic as NewConstraintError
val position = constraintError.position.from
(position as? ArgumentConstraintPosition)?.let {
val expression = it.argument.psiExpression ?: return
val argument = (position as? ArgumentConstraintPosition)?.argument
?: (position as? ReceiverConstraintPosition)?.argument
argument?.let {
val expression = it.psiExpression ?: return
if (reportConstantTypeMismatch(constraintError, expression)) return
trace.report(Errors.TYPE_MISMATCH.on(expression, constraintError.upperType, constraintError.lowerType))
}
@@ -479,6 +479,7 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
fun ResolutionCandidateApplicability.toResolutionStatus(): ResolutionStatus = when (this) {
ResolutionCandidateApplicability.RESOLVED, ResolutionCandidateApplicability.RESOLVED_LOW_PRIORITY -> ResolutionStatus.SUCCESS
ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER -> ResolutionStatus.RECEIVER_TYPE_ERROR
else -> ResolutionStatus.OTHER_ERROR
}
}
@@ -194,7 +194,10 @@ class PSICallResolver(
}
1 -> {
val singleCandidate = result.single()
val resolvedCall = kotlinToResolvedCallTransformer.transformAndReport<D>(singleCandidate, context, trace)
val reportToTrace = singleCandidate.currentStatus.resultingApplicability != ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
val resolvedCall = kotlinToResolvedCallTransformer.transformAndReport<D>(singleCandidate, context, trace.takeIf { reportToTrace })
return SingleOverloadResolutionResult(resolvedCall)
}
else -> {
@@ -225,12 +228,7 @@ class PSICallResolver(
private fun Collection<ResolvedKotlinCall>.areAllCompletedAndInapplicable() =
all {
val applicability = when (it) {
is ResolvedKotlinCall.CompletedResolvedKotlinCall ->
it.completedCall.resolutionStatus.resultingApplicability
is ResolvedKotlinCall.OnlyResolvedKotlinCall ->
it.candidate.status.resultingApplicability
}
val applicability = it.currentStatus.resultingApplicability
applicability == ResolutionCandidateApplicability.INAPPLICABLE || applicability == ResolutionCandidateApplicability.HIDDEN
}