FIR: Fix inference case with flexible captured types
Previsously, errors have been ignored because we ignored errors raised from the completion phase See the comment above the createConstraintPartForLowerBoundAndFlexibleTypeVariable
This commit is contained in:
committed by
teamcityserver
parent
c758069d7c
commit
faa5e46396
@@ -492,4 +492,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
}
|
||||
return intersectionType.withAlternative(secondCandidate)
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.createConstraintPartForLowerBoundAndFlexibleTypeVariable(): KotlinTypeMarker =
|
||||
createFlexibleType(this.makeSimpleTypeDefinitelyNotNullOrNotNull(), this.withNullability(true))
|
||||
}
|
||||
|
||||
+1
-5
@@ -237,11 +237,7 @@ abstract class AbstractTypeCheckerContextForConstraintSystem(override val typeSy
|
||||
when (subType) {
|
||||
is SimpleTypeMarker ->
|
||||
// Foo <: T! -- (Foo!! .. Foo) <: T
|
||||
if (subType.isMarkedNullable()) {
|
||||
subType // prefer nullable type to flexible one: `Foo? <: (T..T?)` => lowerConstraint = `Foo?`
|
||||
} else {
|
||||
createFlexibleType(subType, subType.withNullability(true))
|
||||
}
|
||||
subType.createConstraintPartForLowerBoundAndFlexibleTypeVariable()
|
||||
|
||||
is FlexibleTypeMarker ->
|
||||
// (Foo..Bar) <: T! -- (Foo!! .. Bar) <: T
|
||||
|
||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.types.model
|
||||
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@@ -238,6 +237,17 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun KotlinTypeMarker.extractTypeVariables() = buildSet { extractTypeVariables(this) }
|
||||
|
||||
/**
|
||||
* For case Foo <: (T..T?) return LowerBound for new constraint LowerBound <: T
|
||||
* In FE 1.0, in case nullable it was just Foo?, so constraint was Foo? <: T
|
||||
* But it's not 100% correct because prevent having not-nullable upper constraint on T while initial (Foo? <: (T..T?)) is not violated
|
||||
*
|
||||
* In FIR, we try to have a correct one: (Foo!!..Foo?) <: T
|
||||
*
|
||||
* In future once we have only FIR (or FE 1.0 behavior is fixed) this method should be inlined to the use-site
|
||||
*/
|
||||
fun SimpleTypeMarker.createConstraintPartForLowerBoundAndFlexibleTypeVariable(): KotlinTypeMarker
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -741,6 +741,13 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
override fun getKFunctionTypeConstructor(parametersNumber: Int, isSuspend: Boolean): TypeConstructorMarker {
|
||||
return getKFunctionDescriptor(builtIns, parametersNumber, isSuspend).typeConstructor
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.createConstraintPartForLowerBoundAndFlexibleTypeVariable(): KotlinTypeMarker =
|
||||
if (this.isMarkedNullable()) {
|
||||
this
|
||||
} else {
|
||||
createFlexibleType(this, this.withNullability(true))
|
||||
}
|
||||
}
|
||||
|
||||
fun TypeVariance.convertVariance(): Variance {
|
||||
|
||||
Reference in New Issue
Block a user