Skip to content

Commit 4c9190e

Browse files
authored
Merge pull request #14521 from xedin/rdar-37290898
[CSSolver] Prioritize bindings with fewer default types
2 parents e2765d4 + aff4974 commit 4c9190e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/ConstraintSystem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2758,6 +2758,9 @@ class ConstraintSystem {
27582758
if (!x.hasNonDefaultableBindings())
27592759
return false;
27602760

2761+
if (x.FullyBound || x.SubtypeOfExistentialType)
2762+
return false;
2763+
27612764
llvm::SmallPtrSet<Constraint *, 8> intersection(x.Sources);
27622765
llvm::set_intersect(intersection, y.Sources);
27632766

@@ -2774,7 +2777,9 @@ class ConstraintSystem {
27742777
return x.TypeVar == typeVar;
27752778
}
27762779

2777-
return false;
2780+
// If the only difference is default types,
2781+
// prioritize bindings with fewer of them.
2782+
return x.NumDefaultableBindings < y.NumDefaultableBindings;
27782783
}
27792784

27802785
void foundLiteralBinding(ProtocolDecl *proto) {

test/Constraints/operator.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,10 @@ struct S_35740653 {
194194
func rdar35740653(val: S_35740653) {
195195
let _ = 0...Int(val / .value(1.0 / 42.0)) // Ok
196196
}
197+
198+
protocol P_37290898 {}
199+
struct S_37290898: P_37290898 {}
200+
201+
func rdar37290898(_ arr: inout [P_37290898], _ element: S_37290898?) {
202+
arr += [element].compactMap { $0 } // Ok
203+
}

0 commit comments

Comments
 (0)