[FE 1.0] Return to the old type intersection emptiness check
This reverts commit 8227c4b603.
#KT-53656 Fixed
This commit is contained in:
@@ -426,8 +426,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
|||||||
return withAttributes(attributes.remove(CompilerConeAttributes.Exact))
|
return withAttributes(attributes.remove(CompilerConeAttributes.Exact))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun KotlinTypeMarker.canHaveSubtypes(typeChecker: AbstractTypeChecker): Boolean? = null
|
|
||||||
|
|
||||||
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
|
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
|
||||||
if (this is ErrorTypeConstructor) return createErrorType(reason)
|
if (this is ErrorTypeConstructor) return createErrorType(reason)
|
||||||
if (this is ConeClassLikeLookupTag) return createErrorType("Not found classifier: $classId")
|
if (this is ConeClassLikeLookupTag) return createErrorType("Not found classifier: $classId")
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
|||||||
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
|
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
|
||||||
import org.jetbrains.kotlin.types.error.ErrorUtils;
|
import org.jetbrains.kotlin.types.error.ErrorUtils;
|
||||||
import org.jetbrains.kotlin.types.expressions.*;
|
import org.jetbrains.kotlin.types.expressions.*;
|
||||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker;
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -620,8 +619,7 @@ public class DescriptorResolver {
|
|||||||
@NotNull TypeParameterDescriptor parameter,
|
@NotNull TypeParameterDescriptor parameter,
|
||||||
@NotNull KtTypeParameter typeParameter
|
@NotNull KtTypeParameter typeParameter
|
||||||
) {
|
) {
|
||||||
List<KotlinType> bounds = parameter.getUpperBounds();
|
if (KotlinBuiltIns.isNothing(TypeIntersector.getUpperBoundsAsType(parameter))) {
|
||||||
if (TypeUtilsKt.isEmptyIntersectionTypeCompatible(bounds.toArray(new KotlinTypeMarker[0]))) {
|
|
||||||
trace.report(CONFLICTING_UPPER_BOUNDS.on(typeParameter, parameter));
|
trace.report(CONFLICTING_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -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.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.isInlineClassType
|
import org.jetbrains.kotlin.resolve.isInlineClassType
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.TypeIntersector
|
||||||
import org.jetbrains.kotlin.types.checkEnumsForCompatibility
|
import org.jetbrains.kotlin.types.checkEnumsForCompatibility
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
import org.jetbrains.kotlin.types.expressions.SenselessComparisonChecker.checkSenselessComparisonWithNull
|
import org.jetbrains.kotlin.types.expressions.SenselessComparisonChecker.checkSenselessComparisonWithNull
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isEmptyIntersectionTypeCompatible
|
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
object EqualityCallChecker : CallChecker {
|
object EqualityCallChecker : CallChecker {
|
||||||
@@ -90,7 +90,7 @@ object EqualityCallChecker : CallChecker {
|
|||||||
val leftType = context.trace.getType(left) ?: return
|
val leftType = context.trace.getType(left) ?: return
|
||||||
val rightType = context.trace.getType(right) ?: return
|
val rightType = context.trace.getType(right) ?: return
|
||||||
|
|
||||||
if (isEmptyIntersectionTypeCompatible(leftType, rightType)) {
|
if (TypeIntersector.isIntersectionEmpty(leftType, rightType)) {
|
||||||
val isProperEqualityChecksEnabled =
|
val isProperEqualityChecksEnabled =
|
||||||
context.languageVersionSettings.supportsFeature(LanguageFeature.ProperEqualityChecksInBuilderInferenceCalls)
|
context.languageVersionSettings.supportsFeature(LanguageFeature.ProperEqualityChecksInBuilderInferenceCalls)
|
||||||
val shouldReportWarnings = !isProperEqualityChecksEnabled
|
val shouldReportWarnings = !isProperEqualityChecksEnabled
|
||||||
|
|||||||
+6
@@ -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.results.SimpleConstraintSystem
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.isCallWithSuperReceiver
|
import org.jetbrains.kotlin.resolve.calls.util.isCallWithSuperReceiver
|
||||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
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.types.checker.KotlinTypeRefiner
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -102,6 +104,10 @@ class KotlinResolutionStatelessCallbacksImpl(
|
|||||||
return org.jetbrains.kotlin.resolve.calls.inference.isApplicableCallForBuilderInference(descriptor, languageVersionSettings)
|
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(
|
override fun createConstraintSystemForOverloadResolution(
|
||||||
constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns
|
constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns
|
||||||
): SimpleConstraintSystem = SimpleConstraintSystemImpl(constraintInjector, builtIns, kotlinTypeRefiner, languageVersionSettings)
|
): 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.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
|
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.DataFlowAnalyzer
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isEmptyIntersectionTypeCompatible
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||||
|
|
||||||
object CastDiagnosticsUtil {
|
object CastDiagnosticsUtil {
|
||||||
@@ -225,11 +223,7 @@ object CastDiagnosticsUtil {
|
|||||||
targetType: KotlinType,
|
targetType: KotlinType,
|
||||||
shouldCheckForExactType: Boolean
|
shouldCheckForExactType: Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val types = possibleTypes.map { it.upperIfFlexible() }
|
val intersectedType = TypeIntersector.intersectTypes(possibleTypes.map { it.upperIfFlexible() }) ?: return false
|
||||||
|
|
||||||
if (isEmptyIntersectionTypeCompatible(*types.toTypedArray())) return false
|
|
||||||
|
|
||||||
val intersectedType = intersectTypes(possibleTypes.map { it.upperIfFlexible() })
|
|
||||||
|
|
||||||
return if (shouldCheckForExactType)
|
return if (shouldCheckForExactType)
|
||||||
isExactTypeCast(intersectedType, targetType)
|
isExactTypeCast(intersectedType, targetType)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.jetbrains.kotlin.descriptors.*;
|
|||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
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.ErrorScopeKind;
|
||||||
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
|
import org.jetbrains.kotlin.types.error.ErrorTypeKind;
|
||||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||||
@@ -345,7 +344,7 @@ public class CommonSupertypes {
|
|||||||
}
|
}
|
||||||
if (ins != null) {
|
if (ins != null) {
|
||||||
assert !ins.isEmpty() : "In projections is empty for parameter " + parameterDescriptor + ", type projections " + typeProjections;
|
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) {
|
if (intersection == null) {
|
||||||
return TypeUtils.makeStarProjection(parameterDescriptor);
|
return TypeUtils.makeStarProjection(parameterDescriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-6
@@ -1147,12 +1147,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
boolean isBuilderInferenceContext = context.inferenceSession instanceof BuilderInferenceSession;
|
boolean isBuilderInferenceContext = context.inferenceSession instanceof BuilderInferenceSession;
|
||||||
|
|
||||||
if (
|
if (leftType != null && rightType != null && !TypeIntersector.isIntersectionEmpty(leftType, rightType) && isBuilderInferenceContext) {
|
||||||
leftType != null &&
|
|
||||||
rightType != null &&
|
|
||||||
!TypeUtilsKt.isEmptyIntersectionTypeCompatible(leftType, rightType) &&
|
|
||||||
isBuilderInferenceContext
|
|
||||||
) {
|
|
||||||
context.trace.record(MARKED_EQUALIY_CALL_PROPER_IN_BUILDER_INFERENCE, expression);
|
context.trace.record(MARKED_EQUALIY_CALL_PROPER_IN_BUILDER_INFERENCE, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -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.expressions.typeInfoFactory.noTypeInfo
|
||||||
import org.jetbrains.kotlin.types.typeUtil.containsError
|
import org.jetbrains.kotlin.types.typeUtil.containsError
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
|
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isEmptyIntersectionTypeCompatible
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTypingInternals) : ExpressionTypingVisitor(facade) {
|
class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTypingInternals) : ExpressionTypingVisitor(facade) {
|
||||||
@@ -701,7 +700,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
|
|||||||
reportErrorOn: KtElement
|
reportErrorOn: KtElement
|
||||||
): Boolean {
|
): Boolean {
|
||||||
// TODO : Take smart casts into account?
|
// TODO : Take smart casts into account?
|
||||||
if (isEmptyIntersectionTypeCompatible(type, subjectType)) {
|
if (TypeIntersector.isIntersectionEmpty(type, subjectType)) {
|
||||||
context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType))
|
context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -48,6 +48,8 @@ interface KotlinResolutionStatelessCallbacks {
|
|||||||
fun isBuilderInferenceCall(argument: KotlinCallArgument, parameter: ValueParameterDescriptor): Boolean
|
fun isBuilderInferenceCall(argument: KotlinCallArgument, parameter: ValueParameterDescriptor): Boolean
|
||||||
fun isApplicableCallForBuilderInference(descriptor: CallableDescriptor, languageVersionSettings: LanguageVersionSettings): Boolean
|
fun isApplicableCallForBuilderInference(descriptor: CallableDescriptor, languageVersionSettings: LanguageVersionSettings): Boolean
|
||||||
|
|
||||||
|
fun isOldIntersectionIsEmpty(types: Collection<KotlinType>): Boolean
|
||||||
|
|
||||||
fun createConstraintSystemForOverloadResolution(
|
fun createConstraintSystemForOverloadResolution(
|
||||||
constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns
|
constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns
|
||||||
): SimpleConstraintSystem
|
): SimpleConstraintSystem
|
||||||
|
|||||||
+3
-2
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.types.error.ErrorUtils
|
|||||||
import org.jetbrains.kotlin.types.model.*
|
import org.jetbrains.kotlin.types.model.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.*
|
import org.jetbrains.kotlin.types.typeUtil.*
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.compactIfPossible
|
import org.jetbrains.kotlin.utils.addToStdlib.compactIfPossible
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -900,8 +901,8 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
|
|||||||
* Check if the candidate was already discriminated by `CompatibilityOfTypeVariableAsIntersectionTypePart` resolution part
|
* Check if the candidate was already discriminated by `CompatibilityOfTypeVariableAsIntersectionTypePart` resolution part
|
||||||
* If it's true we shouldn't mark the candidate with warning, but should mark with error, to repeat the existing proper behaviour
|
* If it's true we shouldn't mark the candidate with warning, but should mark with error, to repeat the existing proper behaviour
|
||||||
*/
|
*/
|
||||||
private fun wasPreviouslyDiscriminated(upperTypes: List<KotlinTypeMarker>) =
|
private fun ResolutionCandidate.wasPreviouslyDiscriminated(upperTypes: List<KotlinTypeMarker>) =
|
||||||
isEmptyIntersectionTypeCompatible(*upperTypes.toTypedArray())
|
callComponents.statelessCallbacks.isOldIntersectionIsEmpty(upperTypes.cast())
|
||||||
|
|
||||||
override fun ResolutionCandidate.process(workIndex: Int) = with(getSystem().asConstraintSystemCompleterContext()) {
|
override fun ResolutionCandidate.process(workIndex: Int) = with(getSystem().asConstraintSystemCompleterContext()) {
|
||||||
val constraintSystem = getSystem()
|
val constraintSystem = getSystem()
|
||||||
|
|||||||
+3
-34
@@ -11,11 +11,10 @@ import org.jetbrains.kotlin.types.isDefinitelyEmpty
|
|||||||
import org.jetbrains.kotlin.types.isPossiblyEmpty
|
import org.jetbrains.kotlin.types.isPossiblyEmpty
|
||||||
import org.jetbrains.kotlin.types.model.*
|
import org.jetbrains.kotlin.types.model.*
|
||||||
|
|
||||||
object EmptyIntersectionTypeChecker {
|
internal object EmptyIntersectionTypeChecker {
|
||||||
fun computeEmptyIntersectionEmptiness(
|
fun computeEmptyIntersectionEmptiness(
|
||||||
context: TypeSystemInferenceExtensionContext,
|
context: TypeSystemInferenceExtensionContext,
|
||||||
types: Collection<KotlinTypeMarker>,
|
types: Collection<KotlinTypeMarker>
|
||||||
compatibilityModeEnabled: Boolean = false
|
|
||||||
): EmptyIntersectionTypeInfo? = with(context) {
|
): EmptyIntersectionTypeInfo? = with(context) {
|
||||||
if (types.isEmpty()) return null
|
if (types.isEmpty()) return null
|
||||||
|
|
||||||
@@ -35,11 +34,6 @@ object EmptyIntersectionTypeChecker {
|
|||||||
|
|
||||||
if (!mayCauseEmptyIntersection(secondType)) continue
|
if (!mayCauseEmptyIntersection(secondType)) continue
|
||||||
|
|
||||||
if (compatibilityModeEnabled) {
|
|
||||||
val compatibleKind = computeEmptyIntersectionEmptinessCompatible(firstType, secondType)
|
|
||||||
if (compatibleKind != null) return compatibleKind else continue
|
|
||||||
}
|
|
||||||
|
|
||||||
val secondSubstitutedType = secondType.eraseContainingTypeParameters()
|
val secondSubstitutedType = secondType.eraseContainingTypeParameters()
|
||||||
|
|
||||||
if (!mayCauseEmptyIntersection(secondSubstitutedType) && !mayCauseEmptyIntersection(firstSubstitutedType)) continue
|
if (!mayCauseEmptyIntersection(secondSubstitutedType) && !mayCauseEmptyIntersection(firstSubstitutedType)) continue
|
||||||
@@ -292,31 +286,6 @@ object EmptyIntersectionTypeChecker {
|
|||||||
val type = argument.getType()
|
val type = argument.getType()
|
||||||
return if (type is CapturedTypeMarker) type.typeConstructorProjection() else argument
|
return if (type is CapturedTypeMarker) type.typeConstructorProjection() else argument
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TypeSystemInferenceExtensionContext.computeEmptyIntersectionEmptinessCompatible(
|
|
||||||
firstType: KotlinTypeMarker,
|
|
||||||
secondType: KotlinTypeMarker
|
|
||||||
): EmptyIntersectionTypeInfo? {
|
|
||||||
@Suppress("NAME_SHADOWING")
|
|
||||||
val firstType = firstType.withNullability(false)
|
|
||||||
|
|
||||||
@Suppress("NAME_SHADOWING")
|
|
||||||
val secondType = secondType.withNullability(false)
|
|
||||||
|
|
||||||
val firstErasedType by lazy { firstType.eraseContainingTypeParameters() }
|
|
||||||
val secondErasedType by lazy { secondType.eraseContainingTypeParameters() }
|
|
||||||
|
|
||||||
if (AbstractTypeChecker.areRelatedBySubtyping(this, firstErasedType, secondErasedType))
|
|
||||||
return null
|
|
||||||
|
|
||||||
val canBothHaveSubtypes = firstType.withNullability(false).canHaveSubtypes(AbstractTypeChecker) == true
|
|
||||||
&& secondType.withNullability(false).canHaveSubtypes(AbstractTypeChecker) == true
|
|
||||||
|
|
||||||
if (canBothHaveSubtypes)
|
|
||||||
return null
|
|
||||||
|
|
||||||
return EmptyIntersectionTypeInfo(EmptyIntersectionTypeKind.COMPATIBLE, firstErasedType, secondErasedType)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class EmptyIntersectionTypeInfo(val kind: EmptyIntersectionTypeKind, vararg val casingTypes: KotlinTypeMarker)
|
class EmptyIntersectionTypeInfo(val kind: EmptyIntersectionTypeKind, vararg val casingTypes: KotlinTypeMarker)
|
||||||
@@ -9,11 +9,7 @@ enum class EmptyIntersectionTypeKind(val description: String) {
|
|||||||
MULTIPLE_CLASSES("multiple incompatible classes"),
|
MULTIPLE_CLASSES("multiple incompatible classes"),
|
||||||
INCOMPATIBLE_SUPERTYPES("incompatible supertypes"),
|
INCOMPATIBLE_SUPERTYPES("incompatible supertypes"),
|
||||||
INCOMPATIBLE_TYPE_ARGUMENTS("incompatible type arguments"),
|
INCOMPATIBLE_TYPE_ARGUMENTS("incompatible type arguments"),
|
||||||
SINGLE_FINAL_CLASS("final class and interface"),
|
SINGLE_FINAL_CLASS("final class and interface")
|
||||||
|
|
||||||
// This kind corresponds to migrated logic from old TypeIntersector
|
|
||||||
// Now it's used for determining types compatibility for is/as/equality checks
|
|
||||||
COMPATIBLE("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun EmptyIntersectionTypeKind.isDefinitelyEmpty(): Boolean =
|
fun EmptyIntersectionTypeKind.isDefinitelyEmpty(): Boolean =
|
||||||
|
|||||||
@@ -179,8 +179,6 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
|||||||
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
|
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
|
||||||
fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker
|
fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker
|
||||||
|
|
||||||
fun KotlinTypeMarker.canHaveSubtypes(typeChecker: AbstractTypeChecker): Boolean?
|
|
||||||
|
|
||||||
fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker
|
fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker
|
||||||
fun SimpleTypeMarker.replaceArguments(replacement: (TypeArgumentMarker) -> TypeArgumentMarker): SimpleTypeMarker
|
fun SimpleTypeMarker.replaceArguments(replacement: (TypeArgumentMarker) -> TypeArgumentMarker): SimpleTypeMarker
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.descriptors.*
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
|
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
|
||||||
import org.jetbrains.kotlin.resolve.checkers.EmptyIntersectionTypeChecker
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.checker.*
|
import org.jetbrains.kotlin.types.checker.*
|
||||||
@@ -31,7 +30,6 @@ import org.jetbrains.kotlin.types.model.TypeArgumentMarker
|
|||||||
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
|
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
|
||||||
import kotlin.contracts.ExperimentalContracts
|
import kotlin.contracts.ExperimentalContracts
|
||||||
import kotlin.contracts.contract
|
import kotlin.contracts.contract
|
||||||
|
|
||||||
@@ -397,8 +395,3 @@ fun isUnresolvedType(type: KotlinType): Boolean {
|
|||||||
}
|
}
|
||||||
return type is ErrorType && type.kind.isUnresolved
|
return type is ErrorType && type.kind.isUnresolved
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isEmptyIntersectionTypeCompatible(vararg types: KotlinTypeMarker): Boolean =
|
|
||||||
EmptyIntersectionTypeChecker.computeEmptyIntersectionEmptiness(
|
|
||||||
SimpleClassicTypeSystemContext, types.toList(), compatibilityModeEnabled = true
|
|
||||||
)?.kind == EmptyIntersectionTypeKind.COMPATIBLE
|
|
||||||
|
|||||||
+2
-15
@@ -425,10 +425,11 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
return when (this) {
|
return when (this) {
|
||||||
is SimpleTypeMarker -> this.withNullability(nullable)
|
is SimpleTypeMarker -> this.withNullability(nullable)
|
||||||
is FlexibleTypeMarker -> createFlexibleType(lowerBound().withNullability(nullable), upperBound().withNullability(nullable))
|
is FlexibleTypeMarker -> createFlexibleType(lowerBound().withNullability(nullable), upperBound().withNullability(nullable))
|
||||||
else -> asSimpleType()?.withNullability(nullable) ?: error("Unwrapped type should be simple")
|
else -> error("sealed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun newTypeCheckerState(
|
override fun newTypeCheckerState(
|
||||||
errorTypesEqualToAnything: Boolean,
|
errorTypesEqualToAnything: Boolean,
|
||||||
stubTypesEqualToAnything: Boolean
|
stubTypesEqualToAnything: Boolean
|
||||||
@@ -477,20 +478,6 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
|||||||
return this.replaceAnnotations(Annotations.create(annotationsWithoutExact))
|
return this.replaceAnnotations(Annotations.create(annotationsWithoutExact))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun KotlinTypeMarker.canHaveSubtypes(typeChecker: AbstractTypeChecker): Boolean? {
|
|
||||||
require(this is KotlinType, this::errorMessage)
|
|
||||||
|
|
||||||
val kotlinTypeChecker = object : KotlinTypeChecker {
|
|
||||||
override fun isSubtypeOf(subtype: KotlinType, supertype: KotlinType): Boolean =
|
|
||||||
typeChecker.isSubtypeOf(this@ClassicTypeSystemContext, subtype, supertype)
|
|
||||||
|
|
||||||
override fun equalTypes(a: KotlinType, b: KotlinType): Boolean =
|
|
||||||
typeChecker.equalTypes(this@ClassicTypeSystemContext, a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
return TypeUtils.canHaveSubtypes(kotlinTypeChecker, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun KotlinTypeMarker.hasExactAnnotation(): Boolean {
|
override fun KotlinTypeMarker.hasExactAnnotation(): Boolean {
|
||||||
require(this is UnwrappedType, this::errorMessage)
|
require(this is UnwrappedType, this::errorMessage)
|
||||||
return hasExactInternal(this)
|
return hasExactInternal(this)
|
||||||
|
|||||||
Reference in New Issue
Block a user