mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The compiler's QoI for these cases is horrible, and it's a common pitfall, so be more direct about the fact that this cannot be done. Swift SVN r20613
12 lines
689 B
Swift
12 lines
689 B
Swift
// RUN: %swift -parse %s -verify
|
|
|
|
// Common pitfall: trying to subscript a string with integers.
|
|
func testIntSubscripting(s: String, i: Int) {
|
|
let c1 = s[i] // expected-error{{'subscript' is unavailable: cannot subscript String with an Int}}
|
|
let c2 = s[17] // expected-error{{'subscript' is unavailable: cannot subscript String with an Int}}
|
|
let c3 = s[i...i] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
|
|
let c4 = s[17..<20] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
|
|
let c5 = s[17...20] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
|
|
}
|
|
|