Don't report INFERRED_..._INTO_EMPTY_INTERSECTION with explicit arguments

This commit is contained in:
Mikhail Glukhikh
2022-08-12 16:42:32 +02:00
committed by Space
parent a6b90fcb8e
commit b78106e437
5 changed files with 15 additions and 4 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.ConeTypeParameterBasedTypeVari
import org.jetbrains.kotlin.fir.resolve.inference.ResolvedCallableReferenceAtom
import org.jetbrains.kotlin.fir.resolve.inference.csBuilder
import org.jetbrains.kotlin.fir.resolve.inference.hasBuilderInferenceAnnotation
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeExplicitTypeParameterConstraintPosition
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
import org.jetbrains.kotlin.fir.scopes.FirUnstableSmartcastTypeScope
@@ -34,6 +35,7 @@ import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.visibilityChecker
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.calls.inference.isSubtypeConstraintCompatible
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
@@ -572,7 +574,13 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionStage() {
continue
val emptyIntersectionTypeInfo = candidate.system.getEmptyIntersectionTypeKind(upperTypes) ?: continue
if (variableWithConstraints.constraints.any {
it.kind == ConstraintKind.EQUALITY &&
it.position.initialConstraint.position is ConeExplicitTypeParameterConstraintPosition
}
) {
return
}
sink.yieldDiagnostic(
@Suppress("UNCHECKED_CAST")
InferredEmptyIntersectionDiagnostic(
@@ -900,6 +900,9 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
markCandidateForCompatibilityResolve(needToReportWarning = false)
continue
}
(variableWithConstraints.typeVariable as? TypeVariableFromCallableDescriptor)?.originalTypeParameter?.let { parameter ->
resolvedCall.typeArgumentMappingByOriginal.getTypeArgument(parameter)
} is SimpleTypeArgument -> continue
else -> {
val emptyIntersectionTypeInfo = constraintSystem.getEmptyIntersectionTypeKind(upperTypes) ?: continue
val isInferredEmptyIntersectionForbidden = callComponents.languageVersionSettings.supportsFeature(
@@ -1,5 +1,5 @@
fun test() {
acceptMyRecursive(<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>inferType<!><<!UPPER_BOUND_VIOLATED!>MyRecursive?<!>>())
acceptMyRecursive(inferType<<!UPPER_BOUND_VIOLATED!>MyRecursive?<!>>())
}
fun acceptMyRecursive(value: MyRecursive?) {}
+1 -1
View File
@@ -1,5 +1,5 @@
fun test() {
acceptMyRecursive(<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>inferType<!><<!UPPER_BOUND_VIOLATED, UPPER_BOUND_VIOLATED, UPPER_BOUND_VIOLATED!>MyRecursive?<!>>())
acceptMyRecursive(inferType<<!UPPER_BOUND_VIOLATED, UPPER_BOUND_VIOLATED, UPPER_BOUND_VIOLATED!>MyRecursive?<!>>())
}
fun acceptMyRecursive(value: MyRecursive?) {}
@@ -8,5 +8,5 @@ fun <T : Comparable<T>, S : T?> Expression<in S>.greater(other: T): GreaterOp =
fun foo(countExpr: Expression<Long>) {
countExpr.greater(0)
countExpr.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>greater<!>("0")
countExpr.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION!>greater<!><String, Nothing>("0")
countExpr.greater<String, Nothing>("0")
}