[FE] Add ability to configure PublicDeclaration type approximation configuration

This configuration allows to choose what to do with local and anonymous types
This commit is contained in:
Dmitriy Novozhilov
2022-11-09 10:33:18 +02:00
committed by Space Team
parent 82c39187f6
commit 32f6b71525
7 changed files with 14 additions and 11 deletions
@@ -139,7 +139,7 @@ class ResultTypeResolver(
}
private fun KotlinTypeMarker.toPublicType(): KotlinTypeMarker =
typeApproximator.approximateToSuperType(this, TypeApproximatorConfiguration.PublicDeclaration) ?: this
typeApproximator.approximateToSuperType(this, TypeApproximatorConfiguration.PublicDeclaration.SaveAnonymousTypes) ?: this
private fun Context.isSuitableType(resultType: KotlinTypeMarker, variableWithConstraints: VariableWithConstraints): Boolean {
val filteredConstraints = variableWithConstraints.constraints.filter { isProperTypeForFixation(it.type) }
@@ -52,12 +52,15 @@ open class TypeApproximatorConfiguration {
override val intersectionTypesInContravariantPositions: Boolean get() = true
}
object PublicDeclaration : AllFlexibleSameValue() {
open class PublicDeclaration(override val localTypes: Boolean, override val anonymous: Boolean) : AllFlexibleSameValue() {
override val allFlexible: Boolean get() = true
override val errorType: Boolean get() = true
override val definitelyNotNullType: Boolean get() = false
override val integerLiteralConstantType: Boolean get() = true
override val intersectionTypesInContravariantPositions: Boolean get() = true
object SaveAnonymousTypes : PublicDeclaration(localTypes = false, anonymous = false)
object ApproximateAnonymousTypes : PublicDeclaration(localTypes = false, anonymous = true)
}
sealed class AbstractCapturedTypesApproximation(val approximatedCapturedStatus: CaptureStatus?) :