Skip to content

Commit 45a299a

Browse files
authored
Merge pull request #73960 from xedin/rdar-126960579
[CSBindings] Optional object type variable should be connected to the optional
2 parents 805ed3b + 243cc16 commit 45a299a

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,16 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
16711671
break;
16721672
}
16731673

1674+
case ConstraintKind::OptionalObject: {
1675+
// Type variable that represents an object type of
1676+
// an un-inferred optional is adjacent to a type
1677+
// variable that presents such optional (`bindingTypeVar`
1678+
// in this case).
1679+
if (kind == AllowedBindingKind::Supertypes)
1680+
AdjacentVars.insert({bindingTypeVar, constraint});
1681+
break;
1682+
}
1683+
16741684
default:
16751685
break;
16761686
}

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5424,8 +5424,14 @@ bool ConstraintSystem::repairFailures(
54245424
auto contextualTy = simplifyType(rhs)->getOptionalObjectType();
54255425
if (!lhs->getOptionalObjectType() && !lhs->hasTypeVariable() &&
54265426
contextualTy && !contextualTy->isTypeVariableOrMember()) {
5427-
conversionsOrFixes.push_back(IgnoreContextualType::create(
5428-
*this, lhs, rhs, getConstraintLocator(OEE->getSubExpr())));
5427+
auto *fixLocator = getConstraintLocator(OEE->getSubExpr());
5428+
// If inner expression already has a fix, consider this two-way
5429+
// mismatch as un-salvageable.
5430+
if (hasFixFor(fixLocator))
5431+
return false;
5432+
5433+
conversionsOrFixes.push_back(
5434+
IgnoreContextualType::create(*this, lhs, rhs, fixLocator));
54295435
return true;
54305436
}
54315437
}

test/stmt/foreach.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,13 @@ do {
341341
}
342342
}
343343
}
344+
345+
// https://github.com/apple/swift/issues/73207
346+
do {
347+
func test(_ levels: [Range<Int>]) {
348+
for (i, leaves): (Int, Range<Int>) in levels[8 ..< 15].enumerated() { // Ok
349+
_ = i
350+
_ = leaves
351+
}
352+
}
353+
}

0 commit comments

Comments
 (0)