Skip to content

Commit d82f5c6

Browse files
authored
Merge pull request #14538 from xedin/rdar-37290898-4.1
[4.1][CSSolver] Prioritize bindings with fewer default types
2 parents 583a11d + b8d5810 commit d82f5c6

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
@@ -2639,6 +2639,9 @@ class ConstraintSystem {
26392639
if (!x.hasNonDefaultableBindings())
26402640
return false;
26412641

2642+
if (x.FullyBound || x.SubtypeOfExistentialType)
2643+
return false;
2644+
26422645
llvm::SmallPtrSet<Constraint *, 8> intersection(x.Sources);
26432646
llvm::set_intersect(intersection, y.Sources);
26442647

@@ -2655,7 +2658,9 @@ class ConstraintSystem {
26552658
return x.TypeVar == typeVar;
26562659
}
26572660

2658-
return false;
2661+
// If the only difference is default types,
2662+
// prioritize bindings with fewer of them.
2663+
return x.NumDefaultableBindings < y.NumDefaultableBindings;
26592664
}
26602665

26612666
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)