forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstring_to_substring_conversion.swift
80 lines (65 loc) · 2.56 KB
/
string_to_substring_conversion.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// RUN: %target-swift-frontend -typecheck -verify -fix-string-substring-conversion -swift-version 4 %s
let s = "Hello"
let ss = s[s.startIndex..<s.endIndex]
// CTP_Initialization
do {
let s1: Substring = { return s }() // expected-error {{cannot convert value of type 'String' to specified type 'Substring'}} {{37-37=[]}}
_ = s1
}
// CTP_ReturnStmt
do {
func returnsASubstring() -> Substring {
return s // expected-error {{cannot convert return expression of type 'String' to return type 'Substring'}} {{13-13=[]}}
}
}
// CTP_ThrowStmt
// Doesn't really make sense for this fix-it - see case in diagnoseContextualConversionError:
// The conversion destination of throw is always ErrorType (at the moment)
// if this ever expands, this should be a specific form like () is for
// return.
// CTP_EnumCaseRawValue
// Substrings can't be raw values because they aren't literals.
// CTP_DefaultParameter
do {
func foo(x: Substring = s) {} // expected-error {{default argument value of type 'String' cannot be converted to type 'Substring'}} {{28-28=[]}}
}
// CTP_CalleeResult
do {
func getString() -> String { return s }
let gottenSubstring: Substring = getString() // expected-error {{cannot convert value of type 'String' to specified type 'Substring'}} {{47-47=[]}}
_ = gottenSubstring
}
// CTP_CallArgument
do {
func takesASubstring(_ ss: Substring) {}
takesASubstring(s) // expected-error {{cannot convert value of type 'String' to expected argument type 'Substring'}} {{20-20=[]}}
}
// CTP_ClosureResult
do {
[s].map { (x: String) -> Substring in x } // expected-error {{cannot convert value of type 'String' to closure result type 'Substring'}} {{42-42=[]}}
}
// CTP_ArrayElement
do {
let a: [Substring] = [ s ] // expected-error {{cannot convert value of type 'String' to expected element type 'Substring'}} {{27-27=[]}}
_ = a
}
// CTP_DictionaryKey
do {
let d: [ Substring : Substring ] = [ s : ss ] // expected-error {{cannot convert value of type 'String' to expected dictionary key type 'Substring'}} {{41-41=[]}}
_ = d
}
// CTP_DictionaryValue
do {
let d: [ Substring : Substring ] = [ ss : s ] // expected-error {{cannot convert value of type 'String' to expected dictionary value type 'Substring'}} {{46-46=[]}}
_ = d
}
// CTP_CoerceOperand
do {
let s1: Substring = s as Substring // expected-error {{cannot convert value of type 'String' to type 'Substring' in coercion}} {{24-24=[]}}
_ = s1
}
// CTP_AssignSource
do {
let s1: Substring = s // expected-error {{cannot convert value of type 'String' to specified type 'Substring'}} {{24-24=[]}}
_ = s1
}