Skip to content

Commit 2ddca05

Browse files
committed
Sema: Only consider key path application for member lookup for SubscriptExprs.
Interactions with the rest of the type checker cause use of functions named `subscript` with backtick-quotes to become ambiguous. This is more fully and robustly solved in master by #9989, but that's too invasive a change for 4.0, and we need a spot fix to prevent source compatibility regressions such as SR-5513.
1 parent 1a5205d commit 2ddca05

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
28912891
result.OverallResult = MemberLookupResult::HasResults;
28922892

28932893
// If we're looking for a subscript, consider key path operations.
2894-
if (memberName.isSimpleName(getASTContext().Id_subscript)) {
2894+
if (memberName.isSimpleName(getASTContext().Id_subscript)
2895+
&& (isa<SubscriptExpr>(memberLocator->getAnchor())
2896+
|| isa<KeyPathExpr>(memberLocator->getAnchor()))) {
28952897
result.ViableCandidates.push_back(
28962898
OverloadChoice(baseTy, OverloadChoiceKind::KeyPathApplication));
28972899
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -typecheck -verify %s
2+
// SR-5513
3+
4+
class OTTextView {
5+
func `subscript`(_ sender: Any?) {}
6+
}
7+
8+
class MyTextView: OTTextView {
9+
override func `subscript`(_ sender: Any?) { super.`subscript`(sender) }
10+
}

0 commit comments

Comments
 (0)