forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathStringDiagnostics_without_Foundation.swift
20 lines (16 loc) · 1.25 KB
/
StringDiagnostics_without_Foundation.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// RUN: %target-parse-verify-swift
// Positive and negative tests for String index types
func acceptsForwardIndex<I: ForwardIndex>(_ index: I) {}
func acceptsBidirectionalIndex<I: BidirectionalIndex>(_ index: I) {}
func acceptsRandomAccessIndex<I: RandomAccessIndex>(_ index: I) {}
func testStringIndexTypes(_ s: String) {
acceptsForwardIndex(s.utf8.startIndex)
acceptsBidirectionalIndex(s.utf8.startIndex) // expected-error{{argument type 'String.UTF8View.Index' does not conform to expected type 'BidirectionalIndex'}}
acceptsBidirectionalIndex(s.unicodeScalars.startIndex)
acceptsRandomAccessIndex(s.unicodeScalars.startIndex) // expected-error{{argument type 'String.UnicodeScalarView.Index' does not conform to expected type 'RandomAccessIndex'}}
acceptsBidirectionalIndex(s.characters.startIndex)
acceptsRandomAccessIndex(s.characters.startIndex) // expected-error{{argument type 'String.CharacterView.Index' does not conform to expected type 'RandomAccessIndex'}}
// UTF16View.Index is random-access with Foundation, bidirectional without
acceptsBidirectionalIndex(s.utf16.startIndex)
acceptsRandomAccessIndex(s.utf16.startIndex) // expected-error{{argument type 'String.UTF16View.Index' does not conform to expected type 'RandomAccessIndex'}}
}