[NI] Don't report uninferred type parameter error on special functions

Type parameters can't be specified explicitly for special constructions.
Reporting this error does not help fixing the cause of it and needlessly
reveals implementation details.

^KT-36342 Fixed
This commit is contained in:
Pavel Kirpichenkov
2020-02-06 12:07:13 +03:00
parent fd0c644b6f
commit 95a8060946
13 changed files with 133 additions and 4 deletions
@@ -32,6 +32,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.types.KotlinType
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -391,6 +392,9 @@ class DiagnosticReporterByTrackingStrategy(
}
) return
if (isSpecialFunction(error.resolvedAtom))
return
val expression = when (val atom = error.resolvedAtom.atom) {
is PSIKotlinCall -> atom.psiCall.calleeExpression
is PSIKotlinCallArgument -> atom.valueArgument.getArgumentExpression()
@@ -407,6 +411,14 @@ class DiagnosticReporterByTrackingStrategy(
}
}
private fun isSpecialFunction(atom: ResolvedAtom): Boolean {
if (atom !is ResolvedCallAtom) return false
return ControlStructureTypingUtils.ResolveConstruct.values().any { specialFunction ->
specialFunction.specialFunctionName == atom.candidateDescriptor.name
}
}
private fun reportConstantTypeMismatch(constraintError: NewConstraintError, expression: KtExpression): Boolean {
if (expression is KtConstantExpression) {
val module = context.scope.ownerDescriptor.module