[FE 1.0] Use the old type intersection for type parameter bounds
This is a partial revert of commit bc1c2ada
We have to use old type intersector for emptiness check because
KT-53656 were found. We return to old type intersector usage also
for type parameter bounds to prevent other possible problems.
This commit is contained in:
@@ -56,7 +56,6 @@ import org.jetbrains.kotlin.resolve.source.getPsi
|
|||||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.Variance.*
|
import org.jetbrains.kotlin.types.Variance.*
|
||||||
import org.jetbrains.kotlin.types.checker.intersectWrappedTypes
|
|
||||||
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.error.ErrorScope
|
import org.jetbrains.kotlin.types.error.ErrorScope
|
||||||
@@ -551,9 +550,9 @@ class TypeResolver(
|
|||||||
|
|
||||||
private fun getScopeForTypeParameter(c: TypeResolutionContext, typeParameterDescriptor: TypeParameterDescriptor): MemberScope {
|
private fun getScopeForTypeParameter(c: TypeResolutionContext, typeParameterDescriptor: TypeParameterDescriptor): MemberScope {
|
||||||
return when {
|
return when {
|
||||||
c.checkBounds -> intersectWrappedTypes(typeParameterDescriptor.upperBounds).memberScope
|
c.checkBounds -> TypeIntersector.getUpperBoundsAsType(typeParameterDescriptor).memberScope
|
||||||
else -> LazyScopeAdapter {
|
else -> LazyScopeAdapter {
|
||||||
intersectWrappedTypes(typeParameterDescriptor.upperBounds).memberScope
|
TypeIntersector.getUpperBoundsAsType(typeParameterDescriptor).memberScope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||||
import org.jetbrains.kotlin.types.checker.IntersectionTypeKt;
|
|
||||||
import org.jetbrains.kotlin.utils.DFS;
|
import org.jetbrains.kotlin.utils.DFS;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -58,7 +57,7 @@ public class BoundsSubstitutor {
|
|||||||
|
|
||||||
// todo assert: no loops
|
// todo assert: no loops
|
||||||
for (TypeParameterDescriptor descriptor : topologicallySortTypeParameters(typeParameters)) {
|
for (TypeParameterDescriptor descriptor : topologicallySortTypeParameters(typeParameters)) {
|
||||||
KotlinType upperBoundsAsType = IntersectionTypeKt.intersectWrappedTypes(descriptor.getUpperBounds());
|
KotlinType upperBoundsAsType = TypeIntersector.getUpperBoundsAsType(descriptor);
|
||||||
KotlinType substitutedUpperBoundsAsType = substitutor.substitute(upperBoundsAsType, Variance.INVARIANT);
|
KotlinType substitutedUpperBoundsAsType = substitutor.substitute(upperBoundsAsType, Variance.INVARIANT);
|
||||||
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjectionImpl(substitutedUpperBoundsAsType));
|
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjectionImpl(substitutedUpperBoundsAsType));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
|||||||
import org.jetbrains.kotlin.psi.KtTypeReference;
|
import org.jetbrains.kotlin.psi.KtTypeReference;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTraceContext;
|
import org.jetbrains.kotlin.resolve.BindingTraceContext;
|
||||||
import org.jetbrains.kotlin.resolve.TypeResolutionContext;
|
|
||||||
import org.jetbrains.kotlin.resolve.TypeResolver;
|
import org.jetbrains.kotlin.resolve.TypeResolver;
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession;
|
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession;
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfoFactory;
|
||||||
@@ -46,7 +45,6 @@ import org.jetbrains.kotlin.test.KotlinTestUtils;
|
|||||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment;
|
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment;
|
||||||
import org.jetbrains.kotlin.tests.di.ContainerForTests;
|
import org.jetbrains.kotlin.tests.di.ContainerForTests;
|
||||||
import org.jetbrains.kotlin.tests.di.InjectionKt;
|
import org.jetbrains.kotlin.tests.di.InjectionKt;
|
||||||
import org.jetbrains.kotlin.types.checker.IntersectionTypeKt;
|
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices;
|
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices;
|
||||||
|
|
||||||
@@ -176,7 +174,7 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment {
|
|||||||
assertCommonSupertype("Derived_T<Int>", "DDerived_T<Int>", "Derived_T<Int>");
|
assertCommonSupertype("Derived_T<Int>", "DDerived_T<Int>", "Derived_T<Int>");
|
||||||
assertCommonSupertype("Derived_T<Int>", "DDerived_T<Int>", "DDerived1_T<Int>");
|
assertCommonSupertype("Derived_T<Int>", "DDerived_T<Int>", "DDerived1_T<Int>");
|
||||||
|
|
||||||
assertCommonSupertype("Comparable<Boolean & Int>", "Comparable<Int>", "Comparable<Boolean>");
|
assertCommonSupertype("Comparable<*>", "Comparable<Int>", "Comparable<Boolean>");
|
||||||
assertCommonSupertype("Base_T<out I>", "Base_T<AI>", "Base_T<BI>");
|
assertCommonSupertype("Base_T<out I>", "Base_T<AI>", "Base_T<BI>");
|
||||||
assertCommonSupertype("Base_T<in Int>", "Base_T<Int>", "Base_T<in Int>");
|
assertCommonSupertype("Base_T<in Int>", "Base_T<Int>", "Base_T<in Int>");
|
||||||
assertCommonSupertype("Base_T<in Int>", "Derived_T<Int>", "Base_T<in Int>");
|
assertCommonSupertype("Base_T<in Int>", "Derived_T<Int>", "Base_T<in Int>");
|
||||||
@@ -508,7 +506,7 @@ public class KotlinTypeCheckerTest extends KotlinTestWithEnvironment {
|
|||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
typesToIntersect.add(makeType(type));
|
typesToIntersect.add(makeType(type));
|
||||||
}
|
}
|
||||||
KotlinType result = IntersectionTypeKt.intersectWrappedTypes(typesToIntersect);
|
KotlinType result = TypeIntersector.intersectTypes(typesToIntersect);
|
||||||
// assertNotNull("Intersection is null for " + typesToIntersect, result);
|
// assertNotNull("Intersection is null for " + typesToIntersect, result);
|
||||||
assertEquals(makeType(expected), result);
|
assertEquals(makeType(expected), result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user