Skip to content

Commit 9746fe7

Browse files
authored
Merge pull request swiftlang#73983 from xedin/rdar-126960579-6.0
[6.0][CSBindings] Optional object type variable should be connected to the optional
2 parents d565ac6 + 7725769 commit 9746fe7

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
@@ -1650,6 +1650,16 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
16501650
break;
16511651
}
16521652

1653+
case ConstraintKind::OptionalObject: {
1654+
// Type variable that represents an object type of
1655+
// an un-inferred optional is adjacent to a type
1656+
// variable that presents such optional (`bindingTypeVar`
1657+
// in this case).
1658+
if (kind == AllowedBindingKind::Supertypes)
1659+
AdjacentVars.insert({bindingTypeVar, constraint});
1660+
break;
1661+
}
1662+
16531663
default:
16541664
break;
16551665
}

lib/Sema/CSSimplify.cpp

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

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)