Skip to content

Commit d7a0628

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
1 parent 5545581 commit d7a0628

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
@@ -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
}

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)