Skip to content

Commit e9fcd8c

Browse files
committed
[CSBindings] Optional object type variable should be connected to the optional
If both sides of an `OptionalObject` constraint are un-inferred, their binding sets need to correctly reflect adjacency - a type variable that represents optional would get "object" as an adjacency through its potential binding (the binding is - "object" wrapped in a single level of optional) and "object" type variable needs to get its parent optional type variable added to its adjacency list explicitly. Without this it would be possible to prematurely pick "object" before its parent optional type variable. Resolves: #73207 Resolves: rdar://126960579 (cherry picked from commit d7a0628)
1 parent d69309e commit e9fcd8c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
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
}

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)