Skip to content

Commit 061e69b

Browse files
[Diagnostics] Adjusting SR-13359 diagnostic wording and add tests for labeled tuples
1 parent 0d5bfcb commit 061e69b

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ ERROR(could_not_find_subscript_member_did_you_mean,none,
8989
(Type))
9090

9191
ERROR(could_not_find_subscript_member_tuple, none,
92-
"tuple type %0 element cannot be accessed using subscript",
93-
(Type))
92+
"cannot access element using subscript for tuple type %0; "
93+
"use '.' notation instead", (Type))
9494
ERROR(could_not_find_subscript_member_tuple_did_you_mean_use_dot, none,
95-
"tuple type %0 element cannot be accessed using subscript; "
96-
"did you mean to use '.' to access element?",
97-
(Type))
95+
"cannot access element using subscript for tuple type %0; "
96+
"did you mean to use '.%1'?", (Type, StringRef))
9897

9998
ERROR(could_not_find_enum_case,none,
10099
"enum type %0 has no case %1; did you mean %2?",

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3457,7 +3457,7 @@ bool MissingMemberFailure::diagnoseForSubscriptMemberWithTupleBase() const {
34573457

34583458
emitDiagnostic(
34593459
diag::could_not_find_subscript_member_tuple_did_you_mean_use_dot,
3460-
baseType)
3460+
baseType, literal->getDigitsText())
34613461
.fixItReplace(index->getSourceRange(), OS.str());
34623462
return true;
34633463
}

test/Constraints/members.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -677,15 +677,21 @@ _ = (1, .e) // expected-error {{cannot infer contextual base in reference to mem
677677

678678
// SR-13359
679679
typealias Pair = (Int, Int)
680-
func testSR13359(_ pair: (Int, Int), _ alias: Pair, _ void: Void) {
681-
_ = pair[0] // expected-error {{tuple type '(Int, Int)' element cannot be accessed using subscript; did you mean to use '.' to access element?}} {{11-14=.0}}
682-
_ = pair["strting"] // expected-error {{tuple type '(Int, Int)' element cannot be accessed using subscript}} {{none}}
683-
_ = pair[-1] // expected-error {{tuple type '(Int, Int)' element cannot be accessed using subscript}} {{none}}
684-
_ = pair[1, 1] // expected-error {{tuple type '(Int, Int)' element cannot be accessed using subscript}} {{none}}
680+
func testSR13359(_ pair: (Int, Int), _ alias: Pair, _ void: Void, labeled: (a: Int, b: Int)) {
681+
_ = pair[0] // expected-error {{cannot access element using subscript for tuple type '(Int, Int)'; did you mean to use '.0'?}} {{11-14=.0}}
682+
_ = pair["strting"] // expected-error {{cannot access element using subscript for tuple type '(Int, Int)'; use '.' notation instead}} {{none}}
683+
_ = pair[-1] // expected-error {{cannot access element using subscript for tuple type '(Int, Int)'; use '.' notation instead}} {{none}}
684+
_ = pair[1, 1] // expected-error {{cannot access element using subscript for tuple type '(Int, Int)'; use '.' notation instead}} {{none}}
685685
_ = void[0] // expected-error {{value of type 'Void' has no subscripts}}
686686

687-
_ = alias[0] // expected-error {{tuple type 'Pair' (aka '(Int, Int)') element cannot be accessed using subscript; did you mean to use '.' to access element?}} {{12-15=.0}}
688-
_ = alias["strting"] // expected-error {{tuple type 'Pair' (aka '(Int, Int)') element cannot be accessed using subscript}} {{none}}
689-
_ = alias[-1] // expected-error {{tuple type 'Pair' (aka '(Int, Int)') element cannot be accessed using subscript}} {{none}}
690-
_ = alias[1, 1] // expected-error {{tuple type 'Pair' (aka '(Int, Int)') element cannot be accessed using subscript}} {{none}}
687+
_ = alias[0] // expected-error {{cannot access element using subscript for tuple type 'Pair' (aka '(Int, Int)'); did you mean to use '.0'?}} {{12-15=.0}}
688+
_ = alias["strting"] // expected-error {{cannot access element using subscript for tuple type 'Pair' (aka '(Int, Int)'); use '.' notation instead}} {{none}}
689+
_ = alias[-1] // expected-error {{cannot access element using subscript for tuple type 'Pair' (aka '(Int, Int)'); use '.' notation instead}} {{none}}
690+
_ = alias[1, 1] // expected-error {{cannot access element using subscript for tuple type 'Pair' (aka '(Int, Int)'); use '.' notation instead}} {{none}}
691+
692+
// Labeled tuple base
693+
_ = labeled[0] // expected-error {{cannot access element using subscript for tuple type '(a: Int, b: Int)'; did you mean to use '.0'?}} {{14-17=.0}}
694+
_ = labeled["strting"] // expected-error {{cannot access element using subscript for tuple type '(a: Int, b: Int)'; use '.' notation instead}} {{none}}
695+
_ = labeled[-1] // expected-error {{cannot access element using subscript for tuple type '(a: Int, b: Int)'; use '.' notation instead}} {{none}}
696+
_ = labeled[1, 1] // expected-error {{cannot access element using subscript for tuple type '(a: Int, b: Int)'; use '.' notation instead}} {{none}}
691697
}

0 commit comments

Comments
 (0)