Skip to content

Commit d9642d0

Browse files
authored
Merge pull request #23223 from xedin/followup-to-add-overload-set-cleanup
[ConstraintSystem] Prefer a single local choice over outer alternatives
2 parents a6ec750 + 54290c7 commit d9642d0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,8 +1519,15 @@ void ConstraintSystem::addOverloadSet(Type boundType,
15191519
recordChoice(overloads, choice);
15201520
}
15211521

1522-
for (auto &choice : outerAlternatives)
1523-
recordChoice(overloads, choice);
1522+
if (!outerAlternatives.empty()) {
1523+
// If local scope has a single choice,
1524+
// it should always be preferred.
1525+
if (overloads.size() == 1)
1526+
overloads.front()->setFavored();
1527+
1528+
for (auto &choice : outerAlternatives)
1529+
recordChoice(overloads, choice);
1530+
}
15241531

15251532
addDisjunctionConstraint(overloads, locator, ForgetChoice);
15261533
}

test/Constraints/members.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,16 @@ func rdar_48114578() {
565565
return .valueOf((a, b)) // Ok
566566
}
567567
}
568+
569+
struct S_Min {
570+
var min: Int = 42
571+
}
572+
573+
func min(_: Int, _: Float) -> Int { return 0 }
574+
func min(_: Float, _: Int) -> Int { return 0 }
575+
576+
extension S_Min : CustomStringConvertible {
577+
public var description: String {
578+
return "\(min)" // Ok
579+
}
580+
}

0 commit comments

Comments
 (0)