[FIR] Return error type from common super type if it present
This commit is contained in:
+2
@@ -28,6 +28,8 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext,
|
||||
|
||||
val symbolProvider: FirSymbolProvider get() = session.service()
|
||||
|
||||
override val isErrorTypeAllowed: Boolean get() = false
|
||||
|
||||
override fun nullableNothingType(): SimpleTypeMarker {
|
||||
return StandardClassIds.Nothing(symbolProvider).constructType(emptyArray(), true)
|
||||
}
|
||||
|
||||
+5
@@ -778,6 +778,11 @@ private fun inferenceComponents(session: FirSession, returnTypeCalculator: Retur
|
||||
override fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
|
||||
require(this is ErrorTypeConstructor)
|
||||
return ConeClassErrorType(reason)
|
||||
}
|
||||
}, session, returnTypeCalculator, scopeSession)
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.checker.convertVariance
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
class ErrorTypeConstructor(reason: String) : TypeConstructorMarker
|
||||
class ErrorTypeConstructor(val reason: String) : TypeConstructorMarker
|
||||
|
||||
interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, TypeCheckerProviderContext {
|
||||
val session: FirSession
|
||||
@@ -417,6 +417,10 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
// TODO: Intersection types
|
||||
return false
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.isError(): Boolean {
|
||||
return this is ErrorTypeConstructor
|
||||
}
|
||||
}
|
||||
|
||||
class ConeTypeCheckerContext(override val isErrorTypeEqualsToAnything: Boolean, override val session: FirSession) :
|
||||
|
||||
@@ -34,6 +34,8 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
|
||||
val irBuiltIns: IrBuiltIns
|
||||
|
||||
override val isErrorTypeAllowed: Boolean get() = true
|
||||
|
||||
override fun KotlinTypeMarker.asSimpleType() = this as? SimpleTypeMarker
|
||||
|
||||
override fun KotlinTypeMarker.asFlexibleType() = this as? IrDynamicType
|
||||
@@ -237,6 +239,14 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
return maxInArguments + 1
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
|
||||
throw IllegalStateException("Should not be called")
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.isError(): Boolean {
|
||||
throw IllegalStateException("Should not be called")
|
||||
}
|
||||
|
||||
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? =
|
||||
irBuiltIns.intType as IrSimpleType
|
||||
|
||||
|
||||
+9
@@ -131,6 +131,7 @@ object NewCommonSuperTypeCalculator {
|
||||
|
||||
val explicitSupertypes = filterSupertypes(uniqueTypes)
|
||||
if (explicitSupertypes.size == 1) return explicitSupertypes.single()
|
||||
findErrorTypeInSupertypesIfItIsNeeded(explicitSupertypes)?.let { return it }
|
||||
|
||||
findCommonIntegerLiteralTypesSuperType(explicitSupertypes)?.let { return it }
|
||||
// IntegerLiteralTypeConstructor.findCommonSuperType(explicitSupertypes)?.let { return it }
|
||||
@@ -138,6 +139,14 @@ object NewCommonSuperTypeCalculator {
|
||||
return findSuperTypeConstructorsAndIntersectResult(explicitSupertypes, depth)
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.findErrorTypeInSupertypesIfItIsNeeded(types: List<SimpleTypeMarker>): SimpleTypeMarker? {
|
||||
if (isErrorTypeAllowed) return null
|
||||
for (type in types) {
|
||||
collectAllSupertypes(type).firstOrNull { it.isError() }?.let { return it.toErrorType() }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun TypeSystemCommonSuperTypesContext.findSuperTypeConstructorsAndIntersectResult(
|
||||
types: List<SimpleTypeMarker>,
|
||||
depth: Int
|
||||
|
||||
@@ -30,6 +30,8 @@ import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSystemCommonBackendContext {
|
||||
override val isErrorTypeAllowed: Boolean get() = true
|
||||
|
||||
override fun TypeConstructorMarker.isDenotable(): Boolean {
|
||||
require(this is TypeConstructor, this::errorMessage)
|
||||
return this.isDenotable
|
||||
@@ -56,6 +58,10 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
return this.isError
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
|
||||
throw IllegalStateException("Should not be called")
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.isUninferredParameter(): Boolean {
|
||||
require(this is KotlinType, this::errorMessage)
|
||||
return ErrorUtils.isUninferredParameter(this)
|
||||
@@ -469,6 +475,10 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
return IntegerLiteralTypeConstructor.findCommonSuperType(explicitSupertypes)
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.isError(): Boolean {
|
||||
throw IllegalStateException("Should not be called")
|
||||
}
|
||||
|
||||
override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker {
|
||||
require(this is IntegerLiteralTypeConstructor, this::errorMessage)
|
||||
return this.getApproximatedType().unwrap()
|
||||
|
||||
@@ -67,6 +67,11 @@ interface TypeCheckerProviderContext {
|
||||
}
|
||||
|
||||
interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeFactoryContext, TypeCheckerProviderContext {
|
||||
/*
|
||||
* If set in false then if there is an error type in input types list of `commonSuperType` it will be return
|
||||
* That flag is needed for FIR where there are a problems with recursive class hierarchies
|
||||
*/
|
||||
val isErrorTypeAllowed: Boolean
|
||||
|
||||
fun KotlinTypeMarker.anySuperTypeConstructor(predicate: (TypeConstructorMarker) -> Boolean) =
|
||||
newBaseTypeCheckerContext(false).anySupertype(lowerBoundIfFlexible(), {
|
||||
@@ -84,6 +89,12 @@ interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeF
|
||||
}
|
||||
|
||||
fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker?
|
||||
|
||||
/*
|
||||
* Converts error type constructor to error type
|
||||
* Used only in FIR
|
||||
*/
|
||||
fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker
|
||||
}
|
||||
|
||||
interface TypeSystemInferenceExtensionContextDelegate : TypeSystemInferenceExtensionContext
|
||||
@@ -151,6 +162,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
||||
fun KotlinTypeMarker.asFlexibleType(): FlexibleTypeMarker?
|
||||
|
||||
fun KotlinTypeMarker.isError(): Boolean
|
||||
fun TypeConstructorMarker.isError(): Boolean
|
||||
fun KotlinTypeMarker.isUninferredParameter(): Boolean
|
||||
|
||||
fun FlexibleTypeMarker.asDynamicType(): DynamicTypeMarker?
|
||||
|
||||
Reference in New Issue
Block a user