[FE 1.0] Return to the old type intersection emptiness check

This reverts commit 8227c4b603.
#KT-53656 Fixed
This commit is contained in:
Mikhail Glukhikh
2022-09-06 11:46:47 +02:00
committed by Space
parent 5c09d7838d
commit 3bdd52b64a
15 changed files with 24 additions and 89 deletions
@@ -64,7 +64,6 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
import org.jetbrains.kotlin.types.error.ErrorUtils;
import org.jetbrains.kotlin.types.expressions.*;
import org.jetbrains.kotlin.types.model.KotlinTypeMarker;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
import java.util.*;
@@ -620,8 +619,7 @@ public class DescriptorResolver {
@NotNull TypeParameterDescriptor parameter,
@NotNull KtTypeParameter typeParameter
) {
List<KotlinType> bounds = parameter.getUpperBounds();
if (TypeUtilsKt.isEmptyIntersectionTypeCompatible(bounds.toArray(new KotlinTypeMarker[0]))) {
if (KotlinBuiltIns.isNothing(TypeIntersector.getUpperBoundsAsType(parameter))) {
trace.report(CONFLICTING_UPPER_BOUNDS.on(typeParameter, parameter));
}
}
@@ -16,12 +16,12 @@ import org.jetbrains.kotlin.resolve.calls.inference.BuilderInferenceSession
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.isInlineClassType
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeIntersector
import org.jetbrains.kotlin.types.checkEnumsForCompatibility
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.types.expressions.SenselessComparisonChecker.checkSenselessComparisonWithNull
import org.jetbrains.kotlin.types.typeUtil.builtIns
import org.jetbrains.kotlin.types.typeUtil.isEmptyIntersectionTypeCompatible
import org.jetbrains.kotlin.util.OperatorNameConventions
object EqualityCallChecker : CallChecker {
@@ -90,7 +90,7 @@ object EqualityCallChecker : CallChecker {
val leftType = context.trace.getType(left) ?: return
val rightType = context.trace.getType(right) ?: return
if (isEmptyIntersectionTypeCompatible(leftType, rightType)) {
if (TypeIntersector.isIntersectionEmpty(leftType, rightType)) {
val isProperEqualityChecksEnabled =
context.languageVersionSettings.supportsFeature(LanguageFeature.ProperEqualityChecksInBuilderInferenceCalls)
val shouldReportWarnings = !isProperEqualityChecksEnabled
@@ -39,6 +39,8 @@ import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
import org.jetbrains.kotlin.resolve.calls.results.SimpleConstraintSystem
import org.jetbrains.kotlin.resolve.calls.util.isCallWithSuperReceiver
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeIntersector
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
@@ -102,6 +104,10 @@ class KotlinResolutionStatelessCallbacksImpl(
return org.jetbrains.kotlin.resolve.calls.inference.isApplicableCallForBuilderInference(descriptor, languageVersionSettings)
}
override fun isOldIntersectionIsEmpty(types: Collection<KotlinType>): Boolean {
return TypeIntersector.intersectTypes(types) == null
}
override fun createConstraintSystemForOverloadResolution(
constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns
): SimpleConstraintSystem = SimpleConstraintSystemImpl(constraintInjector, builtIns, kotlinTypeRefiner, languageVersionSettings)
@@ -29,10 +29,8 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
import org.jetbrains.kotlin.types.checker.intersectTypes
import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
import org.jetbrains.kotlin.types.typeUtil.isEmptyIntersectionTypeCompatible
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
object CastDiagnosticsUtil {
@@ -225,11 +223,7 @@ object CastDiagnosticsUtil {
targetType: KotlinType,
shouldCheckForExactType: Boolean
): Boolean {
val types = possibleTypes.map { it.upperIfFlexible() }
if (isEmptyIntersectionTypeCompatible(*types.toTypedArray())) return false
val intersectedType = intersectTypes(possibleTypes.map { it.upperIfFlexible() })
val intersectedType = TypeIntersector.intersectTypes(possibleTypes.map { it.upperIfFlexible() }) ?: return false
return if (shouldCheckForExactType)
isExactTypeCast(intersectedType, targetType)
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.types.checker.IntersectionTypeKt;
import org.jetbrains.kotlin.types.error.ErrorScopeKind;
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
@@ -345,7 +344,7 @@ public class CommonSupertypes {
}
if (ins != null) {
assert !ins.isEmpty() : "In projections is empty for parameter " + parameterDescriptor + ", type projections " + typeProjections;
KotlinType intersection = IntersectionTypeKt.intersectWrappedTypes(ins);
KotlinType intersection = TypeIntersector.intersectTypes(ins);
if (intersection == null) {
return TypeUtils.makeStarProjection(parameterDescriptor);
}
@@ -1147,12 +1147,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
boolean isBuilderInferenceContext = context.inferenceSession instanceof BuilderInferenceSession;
if (
leftType != null &&
rightType != null &&
!TypeUtilsKt.isEmptyIntersectionTypeCompatible(leftType, rightType) &&
isBuilderInferenceContext
) {
if (leftType != null && rightType != null && !TypeIntersector.isIntersectionEmpty(leftType, rightType) && isBuilderInferenceContext) {
context.trace.record(MARKED_EQUALIY_CALL_PROPER_IN_BUILDER_INFERENCE, expression);
}
@@ -46,7 +46,6 @@ import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
import org.jetbrains.kotlin.types.typeUtil.containsError
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
import org.jetbrains.kotlin.types.typeUtil.isEmptyIntersectionTypeCompatible
import java.util.*
class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTypingInternals) : ExpressionTypingVisitor(facade) {
@@ -701,7 +700,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
reportErrorOn: KtElement
): Boolean {
// TODO : Take smart casts into account?
if (isEmptyIntersectionTypeCompatible(type, subjectType)) {
if (TypeIntersector.isIntersectionEmpty(type, subjectType)) {
context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType))
return false
}