Don't do new captured type specific checks for old ones in the type checker

^KT-47143 Fixed
This commit is contained in:
Victor Petukhov
2021-06-08 14:22:39 +03:00
parent 02a56a3077
commit 1b82227308
11 changed files with 62 additions and 2 deletions
@@ -376,8 +376,9 @@ object AbstractTypeChecker {
): Boolean {
val simpleSubArgumentType = subArgumentType.asSimpleType()
if (simpleSubArgumentType !is CapturedTypeMarker || !simpleSubArgumentType.typeConstructor().projection().isStarProjection())
return false
if (simpleSubArgumentType !is CapturedTypeMarker || simpleSubArgumentType.isOldCapturedType()
|| !simpleSubArgumentType.typeConstructor().projection().isStarProjection()
) return false
// Only 'for subtyping' captured types are approximated before adding constraints (see ConstraintInjector.addNewIncorporatedConstraint)
// that can lead to adding problematic constraints like UPPER(Nothing) given by CapturedType(*) <: TypeVariable(A)
if (simpleSubArgumentType.captureStatus() != CaptureStatus.FOR_SUBTYPING) return false
@@ -285,6 +285,7 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker
fun KotlinTypeMarker.withNullability(nullable: Boolean): KotlinTypeMarker
fun CapturedTypeMarker.isOldCapturedType(): Boolean
fun CapturedTypeMarker.typeConstructor(): CapturedTypeConstructorMarker
fun CapturedTypeMarker.captureStatus(): CaptureStatus
fun CapturedTypeMarker.isProjectionNotNull(): Boolean
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
import org.jetbrains.kotlin.resolve.calls.inference.CapturedTypeConstructor
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.resolve.descriptorUtil.*
import org.jetbrains.kotlin.resolve.isInlineClass
@@ -462,6 +463,8 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
return this.captureStatus
}
override fun CapturedTypeMarker.isOldCapturedType(): Boolean = this is CapturedType
override fun KotlinTypeMarker.isNullableType(): Boolean {
require(this is KotlinType, this::errorMessage)
return TypeUtils.isNullableType(this)