Fix SE-0249 source compatibility break

In some situations where both the KeyPath and closure solutions for an expression with a keypath literal were valid, the type checker could not choose between them and Swift would emit an “ambiguous use” error. This change increase the typechecking score of the closure solution so that the typechecker will favor the KeyPath solution, preserving source compatibility for existing APIs.

Fixes rdar://problem/56131416.
This commit is contained in:
Brent Royal-Gordon
2019-10-09 17:15:50 -07:00
parent 1a1f731aad
commit 932128eab6
2 changed files with 21 additions and 0 deletions

View File

@@ -6412,6 +6412,7 @@ done:
auto loc = locator.getBaseLocator();
if (definitelyFunctionType) {
increaseScore(SK_FunctionConversion);
return SolutionKind::Solved;
} else if (!anyComponentsUnresolved ||
(definitelyKeyPathType && capability == ReadOnly)) {