Files
swift-mirror/test/stdlib/StringDiagnostics.swift
Doug Gregor 0b802ce6e9 String: add some unavailable subscript overloads for String with integer (or integer range) indices.
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
2014-07-28 03:50:26 +00:00

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}}
}