Skip to content

Commit 0601498

Browse files
authored
Merge pull request #39831 from hborla/invalid-selector-property
[ConstraintSystem] Don't increase the score for unapplied function references if the expression is an argument to `#selector`.
2 parents 9481130 + 57d0bf8 commit 0601498

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
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
@@ -3000,7 +3000,13 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
30003000
}
30013001

30023002
if (isa<AbstractFunctionDecl>(decl) || isa<TypeDecl>(decl)) {
3003-
if (choice.getFunctionRefKind() == FunctionRefKind::Unapplied) {
3003+
auto anchor = locator->getAnchor();
3004+
// TODO: Instead of not increasing the score for arguments to #selector,
3005+
// a better fix for this is to port over the #selector diagnostics from
3006+
// CSApply to constraint fixes, and not attempt invalid disjunction
3007+
// choices based on the selector kind on the valid code path.
3008+
if (choice.getFunctionRefKind() == FunctionRefKind::Unapplied &&
3009+
!UnevaluatedRootExprs.contains(getAsExpr(anchor))) {
30043010
increaseScore(SK_UnappliedFunction);
30053011
}
30063012
}

test/expr/primary/selector/selector.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,16 @@ extension SomeProtocol {
157157
let _ = #selector(anotherFunction) // expected-error {{cannot use 'anotherFunction' as a selector because protocol 'SomeProtocol' is not exposed to Objective-C}} {{none}}
158158
}
159159

160-
func anotherFunction() {
160+
func anotherFunction() {
161161
print("Hello world!")
162162
}
163163
}
164+
165+
@objc class OverloadedFuncAndProperty {
166+
@objc static func f() {}
167+
@objc var f: Int { 0 }
168+
}
169+
170+
func test() -> Selector {
171+
#selector(OverloadedFuncAndProperty.f)
172+
}

0 commit comments

Comments
 (0)