[FIR] Always fix type variables with UNKNOWN direction
This commit is contained in:
committed by
Space Team
parent
1b27d60307
commit
07567d6748
+7
-7
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImp
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NotEnoughInformationForTypeParameter
|
import org.jetbrains.kotlin.resolve.calls.inference.model.NotEnoughInformationForTypeParameter
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints
|
import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.PostponedAtomWithRevisableExpectedType
|
import org.jetbrains.kotlin.resolve.calls.model.PostponedAtomWithRevisableExpectedType
|
||||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
|
||||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
@@ -262,7 +261,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fixVariable(this, topLevelType, variableWithConstraints, postponedArguments)
|
fixVariable(this, variableWithConstraints)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -388,12 +387,13 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c
|
|||||||
|
|
||||||
private fun fixVariable(
|
private fun fixVariable(
|
||||||
c: ConstraintSystemCompletionContext,
|
c: ConstraintSystemCompletionContext,
|
||||||
topLevelType: KotlinTypeMarker,
|
variableWithConstraints: VariableWithConstraints
|
||||||
variableWithConstraints: VariableWithConstraints,
|
|
||||||
postponedResolveKtPrimitives: List<PostponedResolvedAtom>
|
|
||||||
) {
|
) {
|
||||||
val direction = TypeVariableDirectionCalculator(c, postponedResolveKtPrimitives, topLevelType).getDirection(variableWithConstraints)
|
val resultType = inferenceComponents.resultTypeResolver.findResultType(
|
||||||
val resultType = inferenceComponents.resultTypeResolver.findResultType(c, variableWithConstraints, direction)
|
c,
|
||||||
|
variableWithConstraints,
|
||||||
|
TypeVariableDirectionCalculator.ResolveDirection.UNKNOWN
|
||||||
|
)
|
||||||
val variable = variableWithConstraints.typeVariable
|
val variable = variableWithConstraints.typeVariable
|
||||||
c.fixVariable(variable, resultType, ConeFixVariableConstraintPosition(variable)) // TODO: obtain atom for diagnostics
|
c.fixVariable(variable, resultType, ConeFixVariableConstraintPosition(variable)) // TODO: obtain atom for diagnostics
|
||||||
}
|
}
|
||||||
|
|||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
|
||||||
|
|
||||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
|
||||||
|
|
||||||
import kotlin.internal.OnlyInputTypes
|
|
||||||
|
|
||||||
interface Bound
|
|
||||||
class First : Bound
|
|
||||||
class Second : Bound
|
|
||||||
class Inv<I >(val v: I)
|
|
||||||
class InvB<I : Bound>(val v: I)
|
|
||||||
class In<in C>(v: C)
|
|
||||||
class InB<in C : Bound>(v: C)
|
|
||||||
class Out<out O>(val v: O)
|
|
||||||
class OutB<out O : Bound>(val v: O)
|
|
||||||
|
|
||||||
fun <@OnlyInputTypes M> strictId(arg: M): M = arg
|
|
||||||
fun <@OnlyInputTypes S> strictSelect(arg1: S, arg2: S): S = arg1
|
|
||||||
|
|
||||||
fun testOK(first: First, bound: Bound, second: Second) {
|
|
||||||
strictId(Inv(15))
|
|
||||||
strictId(Inv("foo"))
|
|
||||||
strictId(Inv(first))
|
|
||||||
strictId(InvB(first))
|
|
||||||
strictId(In(first))
|
|
||||||
strictId(InB(first))
|
|
||||||
strictId(Out(first))
|
|
||||||
strictId(OutB(first))
|
|
||||||
strictId(Inv(Inv(Inv(first))))
|
|
||||||
|
|
||||||
strictSelect(Inv(first), Inv(first))
|
|
||||||
strictSelect(InvB(first), InvB(first))
|
|
||||||
|
|
||||||
strictSelect(Out(first), Out(bound))
|
|
||||||
strictSelect(OutB(first), OutB(bound))
|
|
||||||
strictSelect(In(first), In(bound))
|
|
||||||
strictSelect(InB(first), InB(bound))
|
|
||||||
|
|
||||||
val out: Out<Bound> = strictSelect(Out(first), Out(second))
|
|
||||||
val outb: OutB<Bound> = strictSelect(OutB(first), OutB(second))
|
|
||||||
strictSelect<Out<Bound>>(Out(first), Out(second))
|
|
||||||
strictSelect<OutB<Bound>>(OutB(first), OutB(second))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFail(first: First, bound: Bound, second: Second) {
|
|
||||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(InvB(first), InvB(bound))
|
|
||||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(Inv(first), Inv(bound))
|
|
||||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(Out(first), Out(second))
|
|
||||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(In(first), In(second))
|
|
||||||
strictSelect(InB(first), InB(second))
|
|
||||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(Out(Inv(first)), Out(Inv(second)))
|
|
||||||
<!TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR!>strictSelect<!>(In(Inv(first)), In(Inv(second)))
|
|
||||||
}
|
|
||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||||
|
|
||||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||||
|
|||||||
Reference in New Issue
Block a user