Skip to content

Commit e32ad78

Browse files
committed
Revise error for incorrect subscript parameters.
We use subscripts for more than just indexes in Swift these days, so the error message needs to be a bit more general.
1 parent 44de655 commit e32ad78

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ ERROR(cannot_apply_lvalue_binop_to_rvalue,none,
213213
"left side of mutating operator has immutable type %0", (Type))
214214

215215
ERROR(cannot_subscript_with_index,none,
216-
"cannot subscript a value of type %0 with an index of type %1",
216+
"cannot subscript a value of type %0 with a value of type %1",
217217
(Type, Type))
218218

219219
ERROR(cannot_subscript_base,none,

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func r21459429(_ a : Int) {
215215
}
216216

217217

218-
// <rdar://problem/21362748> [WWDC Lab] QoI: cannot subscript a value of type '[Int]?' with an index of type 'Int'
218+
// <rdar://problem/21362748> [WWDC Lab] QoI: cannot subscript a value of type '[Int]?' with a value of type 'Int'
219219
struct StructWithOptionalArray {
220220
var array: [Int]?
221221
}

test/Constraints/subscript.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class C_r25601561 {
110110
// rdar://problem/31977679 - Misleading diagnostics when using subscript with incorrect argument
111111

112112
func r31977679_1(_ properties: [String: String]) -> Any? {
113-
return properties[0] // expected-error {{cannot subscript a value of type '[String : String]' with an index of type 'Int'}}
113+
return properties[0] // expected-error {{cannot subscript a value of type '[String : String]' with a value of type 'Int'}}
114114
}
115115

116116
func r31977679_2(_ properties: [String: String]) -> Any? {

test/decl/func/keyword-argument-defaults.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func testMethods(_ i: Int, x: Y) {
106106

107107
func testSubscripts(_ i: Int, s: String, x: Y) {
108108
var i2 = x[i]
109-
var i3 = x[x: i] // expected-error{{cannot subscript a value of type 'Y' with an index of type '(x: Int)'}}
109+
var i3 = x[x: i] // expected-error{{cannot subscript a value of type 'Y' with a value of type '(x: Int)'}}
110110
// expected-note @-1 {{overloads for 'subscript' exist with these partially matching parameter lists: (Int), (y: String)}}
111111
var s2 = x[y: s]
112112
var s3 = x[s] // expected-error{{cannot convert value of type 'String' to expected argument type 'Int'}}

test/decl/subscript/subscripting.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ struct SubscriptTest2 {
318318
}
319319

320320
func testSubscript1(_ s2 : SubscriptTest2) {
321-
_ = s2["foo"] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with an index of type 'String'}}
321+
_ = s2["foo"] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with a value of type 'String'}}
322322
// expected-note @-1 {{overloads for 'subscript' exist with these partially matching parameter lists: (String, Int), (String, String)}}
323323

324-
let a = s2["foo", 1.0] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with an index of type '(String, Double)'}}
324+
let a = s2["foo", 1.0] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with a value of type '(String, Double)'}}
325325
// expected-note @-1 {{overloads for 'subscript' exist with these partially matching parameter lists: (String, Int), (String, String)}}
326326

327327
_ = s2.subscript("hello", 6)

test/type/types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var d3 : () -> Float = { 4 }
1919
var d4 : () -> Int = { d2 } // expected-error{{function produces expected type 'Int'; did you mean to call it with '()'?}} {{26-26=()}}
2020

2121
var e0 : [Int]
22-
e0[] // expected-error {{cannot subscript a value of type '[Int]' with an index of type '()'}}
22+
e0[] // expected-error {{cannot subscript a value of type '[Int]' with a value of type '()'}}
2323
// expected-note @-1 {{overloads for 'subscript' exist with these partially matching parameter lists: ((UnboundedRange_) -> ()), (Int), (R), (Range<Int>), (Range<Self.Index>)}}
2424

2525
var f0 : [Float]

0 commit comments

Comments
 (0)