Skip to content

Commit 638d702

Browse files
Adding SR-11295 specific tests
1 parent 86ca345 commit 638d702

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

test/expr/cast/as_coerce.swift

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ c3 as C4 // expected-error {{'C3' is not convertible to 'C4'; did you mean to us
8181
// <rdar://problem/19495142> Various incorrect diagnostics for explicit type conversions
8282
1 as Double as Float // expected-error{{cannot convert value of type 'Double' to type 'Float' in coercion}}
8383
1 as Int as String // expected-error{{cannot convert value of type 'Int' to type 'String' in coercion}}
84-
Double(1) as Double as String // expected-error{{cannot convert value of type 'Double' to type 'String' in coercion}}
84+
Double(1) as Double as String // expected-error{{cannot convert value of type 'Double' to type 'String' in coercion}} expected-warning {{redundant cast to 'Double' has no effect}} {{11-21=}}
8585
["awd"] as [Int] // expected-error{{cannot convert value of type 'String' to expected element type 'Int'}}
8686
([1, 2, 1.0], 1) as ([String], Int)
8787
// 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 '
135135
_ = sr6022 as? AnyObject // expected-warning {{conditional cast from '() -> Any' to 'AnyObject' always succeeds}}
136136
_ = sr6022_1 as! Any // expected-warning {{forced cast from '() -> ()' to 'Any' always succeeds; did you mean to use 'as'?}}
137137
_ = sr6022_1 as? Any // expected-warning {{conditional cast from '() -> ()' to 'Any' always succeeds}}
138+
139+
// SR-11295
140+
let sr11295a = "Hello"
141+
_ = sr11295a as String // expected-warning {{redundant cast to 'String' has no effect}} {{14-24=}}
142+
143+
let sr11295b = 1
144+
_ = sr11295b as Int // expected-warning {{redundant cast to 'Int' has no effect}} {{14-21=}}
145+
146+
typealias Type = String
147+
148+
let sr11295c: Type = "Hello Typealias"
149+
_ = sr11295c as String // expected-warning {{redundant cast to 'String' has no effect}} {{14-24=}}
150+
151+
let sr11295d = "Hello Typealias"
152+
_ = sr11295d as Type // expected-warning {{redundant cast to 'Type' (aka 'String') has no effect}} {{14-22=}}
153+
154+
_ = "Hello" as String // Ok
155+
_ = 1 as Int64 // Ok
156+
_ = [] as Set<Int> // Ok
157+
158+
class SR11295A {}
159+
class SR11295B: SR11295A {}
160+
161+
var sr11295ap = SR11295A()
162+
var sr11295bc = SR11295B()
163+
164+
_ = sr11295bc as SR11295A // Ok
165+
166+
_ = 1 as Double as Double // expected-warning {{redundant cast to 'Double' has no effect}} {{17-27=}}
167+
_ = Double(1) as Double // expected-warning {{redundant cast to 'Double' has no effect}} {{15-25=}}
168+
_ = Int(1) as Int // expected-warning {{redundant cast to 'Int' has no effect}} {{12-19=}}
169+
170+
typealias Double1 = Double
171+
typealias Double2 = Double
172+
173+
let sr11295ta1: Double1 = 1.0
174+
_ = sr11295ta1 as Double2 // expected-warning {{redundant cast from 'Double1' (aka 'Double') to 'Double2' (aka 'Double') has no effect}} {{16-27=}}
175+
_ = sr11295ta1 as Double1 // expected-warning {{redundant cast to 'Double1' (aka 'Double') has no effect}} {{16-27=}}

0 commit comments

Comments
 (0)