You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/expr/cast/as_coerce.swift
+39-1Lines changed: 39 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ c3 as C4 // expected-error {{'C3' is not convertible to 'C4'; did you mean to us
81
81
// <rdar://problem/19495142> Various incorrect diagnostics for explicit type conversions
82
82
1asDoubleasFloat // expected-error{{cannot convert value of type 'Double' to type 'Float' in coercion}}
83
83
1asIntasString // expected-error{{cannot convert value of type 'Int' to type 'String' in coercion}}
84
-
Double(1)asDoubleasString // expected-error{{cannot convert value of type 'Double' to type 'String' in coercion}}
84
+
Double(1)asDoubleasString // expected-error{{cannot convert value of type 'Double' to type 'String' in coercion}} expected-warning {{redundant cast to 'Double' has no effect}} {{11-21=}}
85
85
["awd"]as[Int] // expected-error{{cannot convert value of type 'String' to expected element type 'Int'}}
86
86
([1,2,1.0],1)as([String],Int)
87
87
// expected-error@-1 2 {{cannot convert value of type 'Int' to expected element type 'String'}}
@@ -135,3 +135,41 @@ _ = sr6022 as! AnyObject // expected-warning {{forced cast from '() -> Any' to '
135
135
_ = sr6022 as?AnyObject // expected-warning {{conditional cast from '() -> Any' to 'AnyObject' always succeeds}}
136
136
_ = sr6022_1 as!Any // expected-warning {{forced cast from '() -> ()' to 'Any' always succeeds; did you mean to use 'as'?}}
137
137
_ = sr6022_1 as?Any // expected-warning {{conditional cast from '() -> ()' to 'Any' always succeeds}}
138
+
139
+
// SR-11295
140
+
letsr11295a="Hello"
141
+
_ = sr11295a asString // expected-warning {{redundant cast to 'String' has no effect}} {{14-24=}}
142
+
143
+
letsr11295b=1
144
+
_ = sr11295b asInt // expected-warning {{redundant cast to 'Int' has no effect}} {{14-21=}}
145
+
146
+
typealiasType=String
147
+
148
+
letsr11295c:Type="Hello Typealias"
149
+
_ = sr11295c asString // expected-warning {{redundant cast to 'String' has no effect}} {{14-24=}}
150
+
151
+
letsr11295d="Hello Typealias"
152
+
_ = sr11295d asType // expected-warning {{redundant cast to 'Type' (aka 'String') has no effect}} {{14-22=}}
153
+
154
+
_ ="Hello"asString // Ok
155
+
_ =1asInt64 // Ok
156
+
_ =[]asSet<Int> // Ok
157
+
158
+
classSR11295A{}
159
+
classSR11295B:SR11295A{}
160
+
161
+
varsr11295ap=SR11295A()
162
+
varsr11295bc=SR11295B()
163
+
164
+
_ = sr11295bc asSR11295A // Ok
165
+
166
+
_ =1asDoubleasDouble // expected-warning {{redundant cast to 'Double' has no effect}} {{17-27=}}
167
+
_ =Double(1)asDouble // expected-warning {{redundant cast to 'Double' has no effect}} {{15-25=}}
168
+
_ =Int(1)asInt // expected-warning {{redundant cast to 'Int' has no effect}} {{12-19=}}
169
+
170
+
typealiasDouble1=Double
171
+
typealiasDouble2=Double
172
+
173
+
letsr11295ta1:Double1=1.0
174
+
_ = sr11295ta1 asDouble2 // expected-warning {{redundant cast from 'Double1' (aka 'Double') to 'Double2' (aka 'Double') has no effect}} {{16-27=}}
175
+
_ = sr11295ta1 asDouble1 // expected-warning {{redundant cast to 'Double1' (aka 'Double') has no effect}} {{16-27=}}
0 commit comments