FIR: replace ConeKotlinType with more concrete type when possible

This commit is contained in:
Mikhail Glukhikh
2021-12-14 14:36:19 +03:00
committed by TeamCityServer
parent 27d4c745cb
commit 11bbd79c4b
8 changed files with 12 additions and 26 deletions
@@ -183,7 +183,7 @@ object FirJavaGenericVarianceViolationTypeChecker : FirFunctionCallChecker() {
}
}
private fun ConeInferenceContext.isTypeConstructorEqualOrSubClassOf(subType: ConeKotlinType, superType: ConeKotlinType): Boolean {
private fun ConeInferenceContext.isTypeConstructorEqualOrSubClassOf(subType: ConeKotlinType, superType: ConeSimpleKotlinType): Boolean {
return isTypeConstructorEqualOrSubClassOf(subType.typeConstructor(), superType.typeConstructor())
}
@@ -83,8 +83,8 @@ fun checkCasting(
* (i.e. java.lang.String -> kotlin.String) and ignore mappings that go the other way.
*/
private fun isRelated(
aType: ConeKotlinType,
bType: ConeKotlinType,
aType: ConeSimpleKotlinType,
bType: ConeSimpleKotlinType,
aClassSymbol: FirRegularClassSymbol?,
bClassSymbol: FirRegularClassSymbol?,
context: CheckerContext
@@ -97,7 +97,7 @@ private fun isRelated(
return true
}
fun getCorrespondingKotlinClass(type: ConeKotlinType): ConeKotlinType {
fun getCorrespondingKotlinClass(type: ConeSimpleKotlinType): ConeKotlinType {
return context.session.platformClassMapper.getCorrespondingKotlinClass(type.classId)?.defaultType(listOf()) ?: type
}
@@ -108,7 +108,7 @@ private fun isRelated(
AbstractTypeChecker.isSubtypeOf(typeContext, bNormalizedType, aNormalizedType)
}
private fun isFinal(type: ConeKotlinType, session: FirSession): Boolean {
private fun isFinal(type: ConeSimpleKotlinType, session: FirSession): Boolean {
return !type.canHaveSubtypes(session)
}
@@ -275,7 +275,7 @@ fun shouldCheckForExactType(expression: FirTypeOperatorCall, context: CheckerCon
fun isRefinementUseless(
context: CheckerContext,
candidateType: ConeKotlinType,
candidateType: ConeSimpleKotlinType,
targetType: ConeKotlinType,
shouldCheckForExactType: Boolean,
arg: FirExpression,
@@ -292,7 +292,7 @@ fun isRefinementUseless(
}
}
private fun isExactTypeCast(context: CheckerContext, candidateType: ConeKotlinType, targetType: ConeKotlinType): Boolean {
private fun isExactTypeCast(context: CheckerContext, candidateType: ConeSimpleKotlinType, targetType: ConeKotlinType): Boolean {
if (!AbstractTypeChecker.equalTypes(context.session.typeContext, candidateType, targetType, stubTypesEqualToAnything = false))
return false
// See comments at [isUpcast] why we need to check the existence of @ExtensionFunctionType
@@ -62,7 +62,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
visitJump(continueExpression)
}
private fun visitClassAndChildren(klass: FirClass, type: ConeKotlinType) {
private fun visitClassAndChildren(klass: FirClass, type: ConeClassLikeType) {
val typeRef = buildResolvedTypeRef {
this.type = type
}
@@ -139,7 +139,7 @@ internal class KClassValue(value: Value) : ConstantValue<KClassValue.Value>(valu
is Value.NormalClass -> {
val (classId, arrayDimensions) = value.value
val klass = session.symbolProvider.getClassLikeSymbolByClassId(classId)?.fir as? FirRegularClass ?: return null
var type: ConeKotlinType = klass.defaultType().replaceArgumentsWithStarProjections()
var type: ConeClassLikeType = klass.defaultType().replaceArgumentsWithStarProjections()
repeat(arrayDimensions) {
type = type.createArrayType()
}
@@ -264,7 +264,7 @@ class Fir2IrTypeConverter(
return classIdToSymbolMap[classId] ?: getArrayClassSymbol(classId)
}
private fun approximateType(type: ConeKotlinType): ConeKotlinType {
private fun approximateType(type: ConeSimpleKotlinType): ConeKotlinType {
if (type is ConeClassLikeType && type.typeArguments.isEmpty()) return type
val substitutor = object : AbstractConeSubstitutor(session.typeContext) {
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
@@ -61,17 +61,6 @@ fun collectSymbolsForType(type: ConeKotlinType, useSiteSession: FirSession): Lis
return lookupTags.mapNotNull { it.toSymbol(useSiteSession) as? FirClassSymbol<*> }
}
fun lookupSuperTypes(
type: ConeKotlinType,
lookupInterfaces: Boolean,
deep: Boolean,
useSiteSession: FirSession,
substituteTypes: Boolean,
supertypeSupplier: SupertypeSupplier = SupertypeSupplier.Default,
): List<ConeClassLikeType> {
return lookupSuperTypes(collectSymbolsForType(type, useSiteSession), lookupInterfaces, deep, useSiteSession, substituteTypes, supertypeSupplier)
}
fun lookupSuperTypes(
symbols: List<FirClassifierSymbol<*>>,
lookupInterfaces: Boolean,
@@ -22,11 +22,8 @@ import org.jetbrains.kotlin.fir.scopes.FirTypeScope
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.coneTypeSafe
import org.jetbrains.kotlin.types.SmartcastStability
interface Receiver
@@ -34,7 +34,7 @@ class FirDelegatedPropertyInferenceSession(
private val currentConstraintSystem = components.session.inferenceComponents.createConstraintSystem()
override val currentConstraintStorage: ConstraintStorage get() = currentConstraintSystem.currentStorage()
private val unitType: ConeKotlinType = components.session.builtinTypes.unitType.type
private val unitType: ConeClassLikeType = components.session.builtinTypes.unitType.type
private lateinit var resultingConstraintSystem: NewConstraintSystem
private fun ConeKotlinType.containsStubType(): Boolean {