Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,16 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
break;
}

case ConstraintKind::OptionalObject: {
// Type variable that represents an object type of
// an un-inferred optional is adjacent to a type
// variable that presents such optional (`bindingTypeVar`
// in this case).
if (kind == AllowedBindingKind::Supertypes)
AdjacentVars.insert({bindingTypeVar, constraint});
break;
}

default:
break;
}
Expand Down
10 changes: 8 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5424,8 +5424,14 @@ bool ConstraintSystem::repairFailures(
auto contextualTy = simplifyType(rhs)->getOptionalObjectType();
if (!lhs->getOptionalObjectType() && !lhs->hasTypeVariable() &&
contextualTy && !contextualTy->isTypeVariableOrMember()) {
conversionsOrFixes.push_back(IgnoreContextualType::create(
*this, lhs, rhs, getConstraintLocator(OEE->getSubExpr())));
auto *fixLocator = getConstraintLocator(OEE->getSubExpr());
// If inner expression already has a fix, consider this two-way
// mismatch as un-salvageable.
if (hasFixFor(fixLocator))
return false;

conversionsOrFixes.push_back(
IgnoreContextualType::create(*this, lhs, rhs, fixLocator));
return true;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/stmt/foreach.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,13 @@ do {
}
}
}

// https://github.com/apple/swift/issues/73207
do {
func test(_ levels: [Range<Int>]) {
for (i, leaves): (Int, Range<Int>) in levels[8 ..< 15].enumerated() { // Ok
_ = i
_ = leaves
}
}
}