[NI] Get rid of FE 1.0 types in AbstractTypeCheckerContextForConstraintSystem

This commit is contained in:
Dmitriy Novozhilov
2020-08-25 18:39:45 +03:00
parent 686c17a234
commit 527c5a771d
5 changed files with 35 additions and 5 deletions
@@ -316,6 +316,14 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
return this.defaultType return this.defaultType
} }
override fun TypeConstructorMarker.isTypeVariable(): Boolean {
return this is ConeTypeVariableTypeConstructor
}
override fun TypeVariableTypeConstructorMarker.isContainedInInvariantOrContravariantPositions(): Boolean {
return false
}
override fun captureFromExpression(type: KotlinTypeMarker): KotlinTypeMarker? { override fun captureFromExpression(type: KotlinTypeMarker): KotlinTypeMarker? {
return type return type
} }
@@ -76,6 +76,15 @@ class ClassicTypeSystemContextForCS(override val builtIns: KotlinBuiltIns) : Typ
override fun createStubType(typeVariable: TypeVariableMarker): StubTypeMarker { override fun createStubType(typeVariable: TypeVariableMarker): StubTypeMarker {
return StubType(typeVariable.freshTypeConstructor() as TypeConstructor, typeVariable.defaultType().isMarkedNullable()) return StubType(typeVariable.freshTypeConstructor() as TypeConstructor, typeVariable.defaultType().isMarkedNullable())
} }
override fun TypeConstructorMarker.isTypeVariable(): Boolean {
return this is TypeVariableTypeConstructor
}
override fun TypeVariableTypeConstructorMarker.isContainedInInvariantOrContravariantPositions(): Boolean {
require(this is TypeVariableTypeConstructor)
return isContainedInInvariantOrContravariantPositions
}
} }
@@ -5,11 +5,9 @@
package org.jetbrains.kotlin.resolve.calls.inference.components package org.jetbrains.kotlin.resolve.calls.inference.components
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
import org.jetbrains.kotlin.types.AbstractNullabilityChecker import org.jetbrains.kotlin.types.AbstractNullabilityChecker
import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
import org.jetbrains.kotlin.types.checker.NewCapturedType
import org.jetbrains.kotlin.types.model.* import org.jetbrains.kotlin.types.model.*
abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheckerContext(), TypeSystemInferenceExtensionContext { abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheckerContext(), TypeSystemInferenceExtensionContext {
@@ -212,9 +210,13 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
val typeVariableTypeConstructor = typeVariable.typeConstructor() val typeVariableTypeConstructor = typeVariable.typeConstructor()
val subTypeConstructor = subType.typeConstructor() val subTypeConstructor = subType.typeConstructor()
if (subTypeConstructor !is TypeVariableTypeConstructor && typeVariableTypeConstructor is TypeVariableTypeConstructor && typeVariableTypeConstructor.isContainedInInvariantOrContravariantPositions) { if (
if (subType is NewCapturedType) { !subTypeConstructor.isTypeVariable() &&
subType.withNotNullProjection() typeVariableTypeConstructor.isTypeVariable() &&
(typeVariableTypeConstructor as TypeVariableTypeConstructorMarker).isContainedInInvariantOrContravariantPositions()
) {
if (subType.isCapturedType()) {
(subType as CapturedTypeMarker).withNotNullProjection()
} else { } else {
subType.withNullability(false) subType.withNullability(false)
} }
@@ -173,6 +173,9 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
firstCandidate: KotlinTypeMarker, firstCandidate: KotlinTypeMarker,
secondCandidate: KotlinTypeMarker secondCandidate: KotlinTypeMarker
): KotlinTypeMarker ): KotlinTypeMarker
fun TypeConstructorMarker.isTypeVariable(): Boolean
fun TypeVariableTypeConstructorMarker.isContainedInInvariantOrContravariantPositions(): Boolean
} }
@@ -517,6 +517,14 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
errorSupportedOnlyInTypeInference() errorSupportedOnlyInTypeInference()
} }
override fun TypeConstructorMarker.isTypeVariable(): Boolean {
errorSupportedOnlyInTypeInference()
}
override fun TypeVariableTypeConstructorMarker.isContainedInInvariantOrContravariantPositions(): Boolean {
errorSupportedOnlyInTypeInference()
}
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? { override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
explicitSupertypes as List<SimpleType> explicitSupertypes as List<SimpleType>