[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
@@ -76,6 +76,15 @@ class ClassicTypeSystemContextForCS(override val builtIns: KotlinBuiltIns) : Typ
override fun createStubType(typeVariable: TypeVariableMarker): StubTypeMarker {
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
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
import org.jetbrains.kotlin.types.checker.NewCapturedType
import org.jetbrains.kotlin.types.model.*
abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheckerContext(), TypeSystemInferenceExtensionContext {
@@ -212,9 +210,13 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
val typeVariableTypeConstructor = typeVariable.typeConstructor()
val subTypeConstructor = subType.typeConstructor()
if (subTypeConstructor !is TypeVariableTypeConstructor && typeVariableTypeConstructor is TypeVariableTypeConstructor && typeVariableTypeConstructor.isContainedInInvariantOrContravariantPositions) {
if (subType is NewCapturedType) {
subType.withNotNullProjection()
if (
!subTypeConstructor.isTypeVariable() &&
typeVariableTypeConstructor.isTypeVariable() &&
(typeVariableTypeConstructor as TypeVariableTypeConstructorMarker).isContainedInInvariantOrContravariantPositions()
) {
if (subType.isCapturedType()) {
(subType as CapturedTypeMarker).withNotNullProjection()
} else {
subType.withNullability(false)
}