FE: don't approximate type variable based types for public/local declarations
#KT-58618 Fixed
This commit is contained in:
committed by
Space Team
parent
2cfa3d7e0d
commit
6e58ba8f33
+10
-1
@@ -375,7 +375,7 @@ abstract class AbstractTypeApproximator(
|
||||
}
|
||||
|
||||
if (typeConstructor is TypeVariableTypeConstructorMarker) {
|
||||
return if (conf.typeVariable(typeConstructor)) null else type.defaultResult(toSuper)
|
||||
return if (shouldHandleAsTypeVariable(conf, typeConstructor)) null else type.defaultResult(toSuper)
|
||||
}
|
||||
|
||||
if (typeConstructor.isIntegerLiteralConstantTypeConstructor()) {
|
||||
@@ -393,6 +393,15 @@ abstract class AbstractTypeApproximator(
|
||||
return approximateLocalTypes(type, conf, toSuper, depth) // simple classifier type
|
||||
}
|
||||
|
||||
private fun shouldHandleAsTypeVariable(
|
||||
conf: TypeApproximatorConfiguration,
|
||||
typeConstructorMarker: TypeVariableTypeConstructorMarker,
|
||||
): Boolean = when (conf.typeVariable(typeConstructorMarker)) {
|
||||
TypeApproximatorConfiguration.HandleAsTypeVariable.ALWAYS -> true
|
||||
TypeApproximatorConfiguration.HandleAsTypeVariable.K2_ONLY -> isK2
|
||||
TypeApproximatorConfiguration.HandleAsTypeVariable.NEVER -> false
|
||||
}
|
||||
|
||||
private fun approximateDefinitelyNotNullType(
|
||||
type: DefinitelyNotNullTypeMarker,
|
||||
conf: TypeApproximatorConfiguration,
|
||||
|
||||
+13
-3
@@ -38,7 +38,13 @@ open class TypeApproximatorConfiguration {
|
||||
*/
|
||||
open val anonymous = false
|
||||
|
||||
open val typeVariable: (TypeVariableTypeConstructorMarker) -> Boolean = { false }
|
||||
internal enum class HandleAsTypeVariable {
|
||||
ALWAYS,
|
||||
K2_ONLY,
|
||||
NEVER
|
||||
}
|
||||
|
||||
internal open val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable = { HandleAsTypeVariable.NEVER }
|
||||
open fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean =
|
||||
true // false means that this type we can leave as is
|
||||
|
||||
@@ -56,6 +62,8 @@ open class TypeApproximatorConfiguration {
|
||||
override val errorType: Boolean get() = true
|
||||
override val integerLiteralConstantType: Boolean get() = true
|
||||
override val intersectionTypesInContravariantPositions: Boolean get() = true
|
||||
|
||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable get() = { HandleAsTypeVariable.K2_ONLY }
|
||||
}
|
||||
|
||||
open class PublicDeclaration(override val localTypes: Boolean, override val anonymous: Boolean) : AllFlexibleSameValue() {
|
||||
@@ -65,6 +73,8 @@ open class TypeApproximatorConfiguration {
|
||||
override val integerLiteralConstantType: Boolean get() = true
|
||||
override val intersectionTypesInContravariantPositions: Boolean get() = true
|
||||
|
||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable get() = { HandleAsTypeVariable.K2_ONLY }
|
||||
|
||||
object SaveAnonymousTypes : PublicDeclaration(localTypes = false, anonymous = false)
|
||||
object ApproximateAnonymousTypes : PublicDeclaration(localTypes = false, anonymous = true)
|
||||
}
|
||||
@@ -79,7 +89,7 @@ open class TypeApproximatorConfiguration {
|
||||
approximatedCapturedStatus != null && type.captureStatus(ctx) == approximatedCapturedStatus
|
||||
|
||||
override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED
|
||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> Boolean get() = { true }
|
||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable get() = { HandleAsTypeVariable.ALWAYS }
|
||||
}
|
||||
|
||||
object IncorporationConfiguration : AbstractCapturedTypesApproximation(CaptureStatus.FOR_INCORPORATION)
|
||||
@@ -108,7 +118,7 @@ open class TypeApproximatorConfiguration {
|
||||
override val integerLiteralConstantType: Boolean get() = true
|
||||
override val allFlexible: Boolean get() = true
|
||||
override val intersection: IntersectionStrategy get() = IntersectionStrategy.ALLOWED
|
||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> Boolean get() = { true }
|
||||
override val typeVariable: (TypeVariableTypeConstructorMarker) -> HandleAsTypeVariable get() = { HandleAsTypeVariable.ALWAYS }
|
||||
override val errorType: Boolean get() = true
|
||||
|
||||
override fun capturedType(ctx: TypeSystemInferenceExtensionContext, type: CapturedTypeMarker): Boolean = false
|
||||
|
||||
Reference in New Issue
Block a user