Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ class MutableVariableWithConstraints private constructor(
fun addConstraint(constraint: Constraint, inferenceLogger: InferenceLogger?): Pair<Constraint, Boolean> {
val isLowerAndFlexibleTypeWithDefNotNullLowerBound = constraint.isLowerAndFlexibleTypeWithDefNotNullLowerBound()

for (previousConstraint in getConstraintsWithSameTypeHashCode(constraint)) {
if (previousConstraint.type == constraint.type
&& previousConstraint.isNullabilityConstraint == constraint.isNullabilityConstraint
val previousConstraints = getConstraintsWithSameTypeHashCode(constraint)

for (previousConstraint in previousConstraints) {
if (constraintMatchesTypeAndIsNullability(previousConstraint, constraint) &&
newConstraintIsUseless(previousConstraint, constraint)
) {
if (newConstraintIsUseless(previousConstraint, constraint)) {
return previousConstraint to false
}
return previousConstraint to false
}
}

for (previousConstraint in previousConstraints) {
if (constraintMatchesTypeAndIsNullability(previousConstraint, constraint)) {
val isMatchingForSimplification = when (previousConstraint.kind) {
ConstraintKind.LOWER -> constraint.kind.isUpper()
ConstraintKind.UPPER -> constraint.kind.isLower()
Expand Down Expand Up @@ -217,6 +221,10 @@ class MutableVariableWithConstraints private constructor(
clearGroupedConstraintCaches()
}

private fun constraintMatchesTypeAndIsNullability(old: Constraint, new: Constraint): Boolean {
return old.type == new.type && old.isNullabilityConstraint == new.isNullabilityConstraint
}

private fun newConstraintIsUseless(old: Constraint, new: Constraint): Boolean {
// Constraints from declared upper bound are quite special -- they aren't considered as a proper ones
// In other words, user-defined constraints have "higher" priority and here we're trying not to loose them
Expand Down