[FE 1.0] Use the new type intersection to intersect types
This commit is contained in:
committed by
teamcity
parent
941a33a184
commit
bc1c2adae1
+2
-2
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.psi.KtExpression
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.ExplicitSmartCasts
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.ExplicitSmartCasts
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.MultipleSmartCasts
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.MultipleSmartCasts
|
||||||
import org.jetbrains.kotlin.types.TypeIntersector
|
import org.jetbrains.kotlin.types.checker.intersectWrappedTypes
|
||||||
|
|
||||||
internal class KtFe10SmartCastProvider(
|
internal class KtFe10SmartCastProvider(
|
||||||
override val analysisSession: KtFe10AnalysisSession
|
override val analysisSession: KtFe10AnalysisSession
|
||||||
@@ -46,7 +46,7 @@ internal class KtFe10SmartCastProvider(
|
|||||||
|
|
||||||
private fun ExplicitSmartCasts.getKtType(): KtType? {
|
private fun ExplicitSmartCasts.getKtType(): KtType? {
|
||||||
if (this is MultipleSmartCasts) {
|
if (this is MultipleSmartCasts) {
|
||||||
return TypeIntersector.intersectTypes(map.values)?.toKtType(analysisContext)
|
return intersectWrappedTypes(map.values).toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
return defaultType?.toKtType(analysisContext)
|
return defaultType?.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-10
@@ -22,13 +22,10 @@ import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.KtFe1
|
|||||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.getResolutionScope
|
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.psiBased.base.getResolutionScope
|
||||||
import org.jetbrains.kotlin.analysis.api.descriptors.types.base.KtFe10Type
|
import org.jetbrains.kotlin.analysis.api.descriptors.types.base.KtFe10Type
|
||||||
import org.jetbrains.kotlin.analysis.api.descriptors.utils.PublicApproximatorConfiguration
|
import org.jetbrains.kotlin.analysis.api.descriptors.utils.PublicApproximatorConfiguration
|
||||||
import org.jetbrains.kotlin.analysis.api.descriptors.utils.cached
|
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtNamedClassOrObjectSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtPossibleMemberSymbol
|
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.nameOrAnonymous
|
import org.jetbrains.kotlin.analysis.api.symbols.nameOrAnonymous
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.assertIsValidAndAccessible
|
|
||||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||||
@@ -45,6 +42,7 @@ import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
|
|||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||||
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
||||||
|
import org.jetbrains.kotlin.types.checker.intersectWrappedTypes
|
||||||
import org.jetbrains.kotlin.types.error.ErrorType
|
import org.jetbrains.kotlin.types.error.ErrorType
|
||||||
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
|
||||||
@@ -67,37 +65,37 @@ internal class KtFe10TypeProvider(
|
|||||||
|
|
||||||
override val builtinTypes: KtBuiltinTypes by lazy(LazyThreadSafetyMode.PUBLICATION) { KtFe10BuiltinTypes(analysisContext) }
|
override val builtinTypes: KtBuiltinTypes by lazy(LazyThreadSafetyMode.PUBLICATION) { KtFe10BuiltinTypes(analysisContext) }
|
||||||
|
|
||||||
override fun approximateToSuperPublicDenotableType(type: KtType): KtType? {
|
override fun approximateToSuperPublicDenotableType(type: KtType): KtType? {
|
||||||
require(type is KtFe10Type)
|
require(type is KtFe10Type)
|
||||||
return typeApproximator.approximateToSuperType(type.type, PublicApproximatorConfiguration)?.toKtType(analysisContext)
|
return typeApproximator.approximateToSuperType(type.type, PublicApproximatorConfiguration)?.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType {
|
override fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType {
|
||||||
val kotlinType = (getSymbolDescriptor(symbol) as? ClassDescriptor)?.defaultType
|
val kotlinType = (getSymbolDescriptor(symbol) as? ClassDescriptor)?.defaultType
|
||||||
?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_CLASS_TYPE, symbol.nameOrAnonymous.toString())
|
?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_CLASS_TYPE, symbol.nameOrAnonymous.toString())
|
||||||
|
|
||||||
return kotlinType.toKtType(analysisContext)
|
return kotlinType.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun commonSuperType(types: Collection<KtType>): KtType {
|
override fun commonSuperType(types: Collection<KtType>): KtType {
|
||||||
val kotlinTypes = types.map { (it as KtFe10Type).type }
|
val kotlinTypes = types.map { (it as KtFe10Type).type }
|
||||||
return CommonSupertypes.commonSupertype(kotlinTypes).toKtType(analysisContext)
|
return CommonSupertypes.commonSupertype(kotlinTypes).toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getKtType(ktTypeReference: KtTypeReference): KtType {
|
override fun getKtType(ktTypeReference: KtTypeReference): KtType {
|
||||||
val bindingContext = analysisContext.analyze(ktTypeReference, AnalysisMode.PARTIAL)
|
val bindingContext = analysisContext.analyze(ktTypeReference, AnalysisMode.PARTIAL)
|
||||||
val kotlinType = bindingContext[BindingContext.TYPE, ktTypeReference]
|
val kotlinType = bindingContext[BindingContext.TYPE, ktTypeReference]
|
||||||
?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, ktTypeReference.text)
|
?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, ktTypeReference.text)
|
||||||
return kotlinType.toKtType(analysisContext)
|
return kotlinType.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getReceiverTypeForDoubleColonExpression(expression: KtDoubleColonExpression): KtType? {
|
override fun getReceiverTypeForDoubleColonExpression(expression: KtDoubleColonExpression): KtType? {
|
||||||
val bindingContext = analysisContext.analyze(expression, AnalysisMode.PARTIAL)
|
val bindingContext = analysisContext.analyze(expression, AnalysisMode.PARTIAL)
|
||||||
val lhs = bindingContext[BindingContext.DOUBLE_COLON_LHS, expression] ?: return null
|
val lhs = bindingContext[BindingContext.DOUBLE_COLON_LHS, expression] ?: return null
|
||||||
return lhs.type.toKtType(analysisContext)
|
return lhs.type.toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun withNullability(type: KtType, newNullability: KtTypeNullability): KtType {
|
override fun withNullability(type: KtType, newNullability: KtTypeNullability): KtType {
|
||||||
require(type is KtFe10Type)
|
require(type is KtFe10Type)
|
||||||
return type.type.makeNullableAsSpecified(newNullability == KtTypeNullability.NULLABLE).toKtType(analysisContext)
|
return type.type.makeNullableAsSpecified(newNullability == KtTypeNullability.NULLABLE).toKtType(analysisContext)
|
||||||
}
|
}
|
||||||
@@ -153,7 +151,7 @@ internal class KtFe10TypeProvider(
|
|||||||
return bConstructor.supertypes.all { areTypesCompatible(a, it) }
|
return bConstructor.supertypes.all { areTypesCompatible(a, it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val intersectionType = TypeIntersector.intersectTypes(listOf(a, b)) ?: return false
|
val intersectionType = intersectWrappedTypes(listOf(a, b))
|
||||||
val intersectionTypeConstructor = intersectionType.constructor
|
val intersectionTypeConstructor = intersectionType.constructor
|
||||||
|
|
||||||
if (intersectionTypeConstructor is IntersectionTypeConstructor) {
|
if (intersectionTypeConstructor is IntersectionTypeConstructor) {
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ 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
|
||||||
@@ -538,9 +539,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 -> TypeIntersector.getUpperBoundsAsType(typeParameterDescriptor).memberScope
|
c.checkBounds -> intersectWrappedTypes(typeParameterDescriptor.upperBounds).memberScope
|
||||||
else -> LazyScopeAdapter {
|
else -> LazyScopeAdapter {
|
||||||
TypeIntersector.getUpperBoundsAsType(typeParameterDescriptor).memberScope
|
intersectWrappedTypes(typeParameterDescriptor.upperBounds).memberScope
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ 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;
|
||||||
@@ -57,7 +58,7 @@ public class BoundsSubstitutor {
|
|||||||
|
|
||||||
// todo assert: no loops
|
// todo assert: no loops
|
||||||
for (TypeParameterDescriptor descriptor : topologicallySortTypeParameters(typeParameters)) {
|
for (TypeParameterDescriptor descriptor : topologicallySortTypeParameters(typeParameters)) {
|
||||||
KotlinType upperBoundsAsType = TypeIntersector.getUpperBoundsAsType(descriptor);
|
KotlinType upperBoundsAsType = IntersectionTypeKt.intersectWrappedTypes(descriptor.getUpperBounds());
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,9 +20,8 @@ import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
|||||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironmentManagement
|
import org.jetbrains.kotlin.test.KotlinTestWithEnvironmentManagement
|
||||||
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||||
import org.jetbrains.kotlin.types.SimpleType
|
|
||||||
import org.jetbrains.kotlin.types.TypeIntersector
|
|
||||||
import org.jetbrains.kotlin.types.checker.createClassicTypeCheckerState
|
import org.jetbrains.kotlin.types.checker.createClassicTypeCheckerState
|
||||||
|
import org.jetbrains.kotlin.types.checker.intersectTypes
|
||||||
|
|
||||||
class SlowTypeAssertionsEnabledTest : KotlinTestWithEnvironmentManagement() {
|
class SlowTypeAssertionsEnabledTest : KotlinTestWithEnvironmentManagement() {
|
||||||
|
|
||||||
@@ -43,10 +42,10 @@ class SlowTypeAssertionsEnabledTest : KotlinTestWithEnvironmentManagement() {
|
|||||||
val builtIns = DefaultBuiltIns.Instance
|
val builtIns = DefaultBuiltIns.Instance
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val superType = TypeIntersector.intersectTypes(listOf(builtIns.charSequence.defaultType, builtIns.comparable.defaultType))
|
val superType = intersectTypes(listOf(builtIns.charSequence.defaultType, builtIns.comparable.defaultType))
|
||||||
AbstractNullabilityChecker.isPossibleSubtype(
|
AbstractNullabilityChecker.isPossibleSubtype(
|
||||||
createClassicTypeCheckerState(isErrorTypeEqualsToAnything = true), builtIns.annotationType,
|
createClassicTypeCheckerState(isErrorTypeEqualsToAnything = true), builtIns.annotationType,
|
||||||
superType as SimpleType
|
superType
|
||||||
)
|
)
|
||||||
} catch (e: AssertionError) {
|
} catch (e: AssertionError) {
|
||||||
assertEquals("Not singleClassifierType superType: {CharSequence & Comparable<T>}", e.message)
|
assertEquals("Not singleClassifierType superType: {CharSequence & Comparable<T>}", e.message)
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ 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;
|
||||||
|
|
||||||
@@ -505,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 = TypeIntersector.intersectTypes(typesToIntersect);
|
KotlinType result = IntersectionTypeKt.intersectWrappedTypes(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