Skip to content

Commit beaaee7

Browse files
committed
[ConstraintSystem] Don't increase the score for unapplied function references
if the expression is an argument to `#selector`. For `#selector` arguments, functions and properties are syntactically distinct with the getter/setter label, so the solver should not unconditionally prefer properties to unapplied functions. A better fix for this is to port over the `#selector` diagnostics from CSApply, and not attempt invalid disjunction choices based on the selector kind on the valid code path.
1 parent 710c6b8 commit beaaee7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3464,7 +3464,8 @@ namespace {
34643464
// Note that the subexpression of a #selector expression is
34653465
// unevaluated.
34663466
if (auto sel = dyn_cast<ObjCSelectorExpr>(expr)) {
3467-
CG.getConstraintSystem().UnevaluatedRootExprs.insert(sel->getSubExpr());
3467+
auto *subExpr = sel->getSubExpr()->getSemanticsProvidingExpr();
3468+
CG.getConstraintSystem().UnevaluatedRootExprs.insert(subExpr);
34683469
}
34693470

34703471
// Check an objc key-path expression, which fills in its semantic

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,13 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
29162916
}
29172917

29182918
if (isa<AbstractFunctionDecl>(decl) || isa<TypeDecl>(decl)) {
2919-
if (choice.getFunctionRefKind() == FunctionRefKind::Unapplied) {
2919+
auto anchor = locator->getAnchor();
2920+
// TODO: Instead of not increasing the score for arguments to #selector,
2921+
// a better fix for this is to port over the #selector diagnostics from
2922+
// CSApply to constraint fixes, and not attempt invalid disjunction
2923+
// choices based on the selector kind on the valid code path.
2924+
if (choice.getFunctionRefKind() == FunctionRefKind::Unapplied &&
2925+
!UnevaluatedRootExprs.contains(getAsExpr(anchor))) {
29202926
increaseScore(SK_UnappliedFunction);
29212927
}
29222928
}

0 commit comments

Comments
 (0)