Skip to content

Commit 5ab5c60

Browse files
committed
[Sema] Don't diagnose DynamicSubscriptExpr's arg as tuple
Register DynamicSubscriptExpr's index expression as a call argument in MiscDiagnostics to avoid it being diagnosed as a single element labelled tuple. Resolves SR-12799.
1 parent de3a67a commit 5ab5c60

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
137137
if (auto *SE = dyn_cast<SubscriptExpr>(E))
138138
CallArgs.insert(SE->getIndex());
139139

140+
if (auto *DSE = dyn_cast<DynamicSubscriptExpr>(E))
141+
CallArgs.insert(DSE->getIndex());
142+
140143
if (auto *KPE = dyn_cast<KeyPathExpr>(E)) {
141144
for (auto Comp : KPE->getComponents()) {
142145
if (auto *Arg = Comp.getIndexExpr())

test/Constraints/dynamic_lookup.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ class C1 {
371371
@objc subscript(unambiguousSubscript _: String) -> Int { return 0 } // expected-note {{found this candidate}}
372372
}
373373

374+
class C2 {
375+
@objc subscript(singleCandidate _: Int) -> Int { return 0 }
376+
}
377+
374378
func testAnyObjectAmbiguity(_ x: AnyObject) {
375379
_ = x.ambiguousProperty // expected-error {{ambiguous use of 'ambiguousProperty'}}
376380
_ = x.unambiguousProperty
@@ -384,6 +388,9 @@ func testAnyObjectAmbiguity(_ x: AnyObject) {
384388
_ = x.ambiguousMethodParam // expected-error {{ambiguous use of 'ambiguousMethodParam'}}
385389
_ = x.unambiguousMethodParam
386390

391+
// SR-12799: Don't emit a "single-element" tuple error.
392+
_ = x[singleCandidate: 0]
393+
387394
_ = x[ambiguousSubscript: 0] // expected-error {{ambiguous use of 'subscript(ambiguousSubscript:)'}}
388395

389396
// FIX-ME(SR-8611): This is currently ambiguous but shouldn't be.

0 commit comments

Comments
 (0)