Skip to content

Commit 2701d43

Browse files
committed
[CSBindings] Prefer key path type over a disjunction if key path is resolved
If key path type has bindings and is no longer delayed it means that it's fully resolved and ready to be bound (even though value type might not be resolved yet).
1 parent 144ede7 commit 2701d43

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,11 @@ bool BindingSet::favoredOverDisjunction(Constraint *disjunction) const {
12571257
if (Bindings.empty())
12581258
return false;
12591259

1260+
// Always prefer key path type if it has bindings and is not delayed
1261+
// because that means that it was possible to infer its capability.
1262+
if (TypeVar->getImpl().isKeyPathType())
1263+
return true;
1264+
12601265
return !involvesTypeVariables();
12611266
}
12621267

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %scale-test --begin 2 --end 10 --step 1 --select NumConstraintScopes %s
2+
// REQUIRES: asserts,no_asan
3+
4+
struct Test {
5+
var id: String
6+
}
7+
8+
func test(data: [Test]) -> Set<String> {
9+
Set(data.map(\.id) +
10+
%for i in range(0, N):
11+
data.map(\.id) +
12+
%end
13+
data.map(\.id))
14+
}

0 commit comments

Comments
 (0)