K1: add forgotten INFERRED_INTO_DECLARED_UPPER_BOUNDS for incorporation case
#KT-56169 Fixed
This commit is contained in:
committed by
Space Team
parent
ba2d896c01
commit
97bec59bc9
+16
-10
@@ -14,10 +14,7 @@ import org.jetbrains.kotlin.resolve.calls.model.*
|
|||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.error.ErrorTypeKind
|
import org.jetbrains.kotlin.types.error.ErrorTypeKind
|
||||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
import org.jetbrains.kotlin.types.model.*
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
|
|
||||||
import org.jetbrains.kotlin.types.model.safeSubstitute
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
|
||||||
@@ -453,14 +450,23 @@ class KotlinConstraintSystemCompleter(
|
|||||||
|
|
||||||
private fun reportWarningIfFixedIntoDeclaredUpperBounds(
|
private fun reportWarningIfFixedIntoDeclaredUpperBounds(
|
||||||
diagnosticsHolder: KotlinDiagnosticsHolder,
|
diagnosticsHolder: KotlinDiagnosticsHolder,
|
||||||
variableWithConstraints: VariableWithConstraints
|
variableWithConstraints: VariableWithConstraints,
|
||||||
|
resultType: KotlinTypeMarker
|
||||||
) {
|
) {
|
||||||
val areAllConstraintFromDeclaredUpperBounds = variableWithConstraints.constraints.all {
|
var upperBoundType: KotlinTypeMarker? = null
|
||||||
val position = it.position.from
|
val constraintFromDeclaredUpperBoundExists = variableWithConstraints.constraints.any { constraint ->
|
||||||
position is BuilderInferenceSubstitutionConstraintPosition<*, *> && position.isFromNotSubstitutedDeclaredUpperBound
|
val position = constraint.position.from.let { basicPosition ->
|
||||||
|
if (basicPosition is IncorporationConstraintPosition) basicPosition.from else basicPosition
|
||||||
|
}
|
||||||
|
if (position is BuilderInferenceSubstitutionConstraintPosition<*, *> && position.isFromNotSubstitutedDeclaredUpperBound) {
|
||||||
|
upperBoundType = constraint.type
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (areAllConstraintFromDeclaredUpperBounds) {
|
if (constraintFromDeclaredUpperBoundExists && upperBoundType == resultType) {
|
||||||
diagnosticsHolder.addDiagnostic(
|
diagnosticsHolder.addDiagnostic(
|
||||||
KotlinConstraintSystemDiagnostic(InferredIntoDeclaredUpperBounds(variableWithConstraints.typeVariable))
|
KotlinConstraintSystemDiagnostic(InferredIntoDeclaredUpperBounds(variableWithConstraints.typeVariable))
|
||||||
)
|
)
|
||||||
@@ -478,7 +484,7 @@ class KotlinConstraintSystemCompleter(
|
|||||||
val variable = variableWithConstraints.typeVariable
|
val variable = variableWithConstraints.typeVariable
|
||||||
val resolvedAtom = findResolvedAtomBy(variable, topLevelAtoms) ?: topLevelAtoms.firstOrNull()
|
val resolvedAtom = findResolvedAtomBy(variable, topLevelAtoms) ?: topLevelAtoms.firstOrNull()
|
||||||
|
|
||||||
reportWarningIfFixedIntoDeclaredUpperBounds(diagnosticsHolder, variableWithConstraints)
|
reportWarningIfFixedIntoDeclaredUpperBounds(diagnosticsHolder, variableWithConstraints, resultType)
|
||||||
|
|
||||||
c.fixVariable(variable, resultType, FixVariableConstraintPositionImpl(variable, resolvedAtom))
|
c.fixVariable(variable, resultType, FixVariableConstraintPositionImpl(variable, resolvedAtom))
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
// ISSUE: KT-50520
|
// ISSUE: KT-50520
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
buildList {
|
<!INFERRED_INTO_DECLARED_UPPER_BOUNDS!>buildList<!> {
|
||||||
val foo = { first() }
|
val foo = { first() }
|
||||||
add(0, foo)
|
add(0, foo)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user