Skip to content

Commit 86ca345

Browse files
Fixing warning UnnecessaryCoercion tests
1 parent 16bd889 commit 86ca345

24 files changed

+87
-85
lines changed

test/ClangImporter/Darwin_test.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ _ = nil as Fract? // expected-error{{use of undeclared type 'Fract'}}
99
_ = nil as Darwin.Fract? // okay
1010

1111
_ = 0 as OSErr
12-
_ = noErr as OSStatus // noErr is from the overlay
12+
// noErr is from the overlay
13+
_ = noErr as OSStatus // expected-warning {{redundant cast to 'OSStatus' (aka 'Int32') has no effect}} {{11-23=}}
1314
_ = 0 as UniChar
1415

1516
_ = ProcessSerialNumber()

test/ClangImporter/MixedSource/mixed-target-using-header.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ func testSuppressed() {
5353
#endif
5454

5555
func testMacro() {
56-
_ = CONSTANT as CInt
56+
_ = CONSTANT as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{16-24=}}
5757
}
5858

5959
func testFoundationOverlay() {
6060
_ = NSUTF8StringEncoding // no ambiguity
61-
_ = NSUTF8StringEncoding as UInt // and we should get the overlay version
61+
// and we should get the overlay version
62+
_ = NSUTF8StringEncoding as UInt // expected-warning {{redundant cast to 'UInt' has no effect}} {{28-36=}}
6263
}
6364

6465
#if !SILGEN

test/ClangImporter/Security_test.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import Security
66

7-
_ = kSecClass as CFString
8-
_ = kSecClassGenericPassword as CFString
7+
_ = kSecClass as CFString // expected-warning {{redundant cast to 'CFString' has no effect}} {{15-27=}}
8+
_ = kSecClassGenericPassword as CFString // expected-warning {{redundant cast to 'CFString' has no effect}} {{30-42=}}
99
_ = kSecClassGenericPassword as CFDictionary // expected-error {{'CFString?' is not convertible to 'CFDictionary'}} {{30-32=as!}}
1010

1111
func testIntegration() {

test/ClangImporter/attr-swift_private.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public func testTopLevel() {
102102

103103
_ = __PrivAnonymousA
104104
_ = __E0PrivA
105-
_ = __PrivE1A as __PrivE1
105+
_ = __PrivE1A as __PrivE1 // expected-warning {{redundant cast to '__PrivE1' has no effect}} {{15-27=}}
106106
_ = NSEnum.__privA
107107
_ = NSEnum.B
108108
_ = NSOptions.__privA

test/ClangImporter/cf.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ func testTollFree1(_ ccmduct: CCMutableDuct) {
9090
}
9191

9292
func testChainedAliases(_ fridge: CCRefrigerator) {
93-
_ = fridge as CCRefrigerator
93+
_ = fridge as CCRefrigerator // expected-warning {{redundant cast to 'CCRefrigerator' has no effect}} {{14-32=}}
9494

95-
_ = fridge as CCFridge
95+
_ = fridge as CCFridge // expected-warning {{redundant cast to 'CCFridge' (aka 'CCRefrigerator') has no effect}} {{14-26=}}
9696
_ = fridge as CCFridgeRef // expected-error{{'CCFridgeRef' has been renamed to 'CCFridge'}} {{17-28=CCFridge}}
9797
}
9898

test/ClangImporter/cfuncs_parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func test_cfunc2(_ i: Int) {
1515
#else
1616
let f = cfunc2(i, 17)
1717
#endif
18-
_ = f as Float
18+
_ = f as Float // expected-warning {{redundant cast to 'Float' has no effect}} {{9-18=}}
1919
cfunc2(b:17, a:i) // expected-error{{extraneous argument labels 'b:a:' in call}}
2020
// expected-error@-1 {{cannot convert value of type 'Int' to expected argument type 'Int32'}}
2121
cfunc2(17, i) // expected-error{{cannot convert value of type 'Int' to expected argument type 'Int32'}}

test/ClangImporter/ctypes_parse.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func testAnonEnum() {
4747
func testAnonEnumSmall() {
4848
var a = AnonConstSmall1
4949
a = AnonConstSmall2
50-
_ = a as Int
50+
_ = a as Int // expected-warning {{redundant cast to 'Int' has no effect}} {{9-16=}}
5151
}
5252

5353
func testPoint() -> Float {
@@ -141,14 +141,14 @@ func testImportStddefTypes() {
141141
let t2_unqual: Int = size_t_test
142142
let t3_unqual: Int = rsize_t_test
143143

144-
_ = t1_unqual as ctypes.ptrdiff_t
145-
_ = t2_unqual as ctypes.size_t
146-
_ = t3_unqual as ctypes.rsize_t
144+
_ = t1_unqual as ctypes.ptrdiff_t // expected-warning {{redundant cast to 'ptrdiff_t' (aka 'Int') has no effect}} {{17-37=}}
145+
_ = t2_unqual as ctypes.size_t // expected-warning {{redundant cast to 'size_t' (aka 'Int') has no effect}} {{17-34=}}
146+
_ = t3_unqual as ctypes.rsize_t // expected-warning {{redundant cast to 'rsize_t' (aka 'Int') has no effect}} {{17-35=}}
147147
}
148148

149149
func testImportSysTypesTypes() {
150150
let t1_unqual: Int = ssize_t_test
151-
_ = t1_unqual as ctypes.ssize_t
151+
_ = t1_unqual as ctypes.ssize_t // expected-warning {{redundant cast to 'ssize_t' (aka 'Int') has no effect}} {{17-35=}}
152152
}
153153

154154
func testImportOSTypesTypes() {
@@ -198,7 +198,7 @@ func testFunctionPointers() {
198198
let fp = getFunctionPointer()
199199
useFunctionPointer(fp)
200200

201-
_ = fp as (@convention(c) (CInt) -> CInt)?
201+
_ = fp as (@convention(c) (CInt) -> CInt)? // expected-warning {{redundant cast to '(@convention(c) (CInt) -> CInt)?' (aka 'Optional<@convention(c) (Int32) -> Int32>') has no effect}} {{10-46=}}
202202

203203
let wrapper: FunctionPointerWrapper = FunctionPointerWrapper(a: nil, b: nil)
204204
_ = FunctionPointerWrapper(a: fp, b: fp)

test/ClangImporter/ctypes_parse_objc.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ func testImportMacTypes() {
7171

7272
func testImportCFTypes() {
7373
let t1_unqual: UInt = CFTypeID_test
74-
_ = t1_unqual as CoreFoundation.CFTypeID
74+
_ = t1_unqual as CoreFoundation.CFTypeID // expected-warning {{redundant cast to 'CFTypeID' (aka 'UInt') has no effect}} {{17-44=}}
7575

7676
let t2_unqual: UInt = CFOptionFlags_test
77-
_ = t2_unqual as CoreFoundation.CFOptionFlags
77+
_ = t2_unqual as CoreFoundation.CFOptionFlags // expected-warning {{redundant cast to 'CFOptionFlags' (aka 'UInt') has no effect}} {{17-49=}}
7878

7979
let t3_unqual: UInt = CFHashCode_test
80-
_ = t3_unqual as CoreFoundation.CFHashCode
80+
_ = t3_unqual as CoreFoundation.CFHashCode // expected-warning {{redundant cast to 'CFHashCode' (aka 'UInt') has no effect}} {{17-46=}}
8181

8282
let t4_unqual: Int = CFIndex_test
83-
_ = t4_unqual as CoreFoundation.CFIndex
83+
_ = t4_unqual as CoreFoundation.CFIndex // expected-warning {{redundant cast to 'CFIndex' (aka 'Int') has no effect}} {{17-43=}}
8484
}
8585

8686
func testImportSEL() {

test/ClangImporter/macros.swift

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ func testNil() {
103103
}
104104

105105
func testBitwiseOps() {
106-
_ = DISPATCH_TIME_FOREVER as CUnsignedLongLong
106+
_ = DISPATCH_TIME_FOREVER as CUnsignedLongLong // expected-warning {{redundant cast to 'CUnsignedLongLong' (aka 'UInt64') has no effect}} {{29-50=}}
107107
_ = (BIT_SHIFT_1 | BIT_SHIFT_2) as CInt
108-
_ = BIT_SHIFT_3 as CLongLong
109-
_ = BIT_SHIFT_4 as CUnsignedInt
108+
_ = BIT_SHIFT_3 as CLongLong // expected-warning {{redundant cast to 'CLongLong' (aka 'Int64') has no effect}} {{19-32=}}
109+
_ = BIT_SHIFT_4 as CUnsignedInt // expected-warning {{redundant cast to 'CUnsignedInt' (aka 'UInt32') has no effect}} {{19-35=}}
110110

111-
_ = RSHIFT_ONE as CUnsignedInt
111+
_ = RSHIFT_ONE as CUnsignedInt // expected-warning {{redundant cast to 'CUnsignedInt' (aka 'UInt32') has no effect}} {{18-34=}}
112112
_ = RSHIFT_INVALID // expected-error {{use of unresolved identifier 'RSHIFT_INVALID'}}
113113

114-
_ = XOR_HIGH as CUnsignedLongLong
114+
_ = XOR_HIGH as CUnsignedLongLong // expected-warning {{redundant cast to 'CUnsignedLongLong' (aka 'UInt64') has no effect}} {{16-37=}}
115115

116116
var attributes = 0 as CInt
117117
attributes |= ATTR_BOLD
@@ -121,30 +121,30 @@ func testBitwiseOps() {
121121
}
122122

123123
func testIntegerArithmetic() {
124-
_ = ADD_ZERO as CInt
125-
_ = ADD_ONE as CInt
126-
_ = ADD_TWO as CInt
127-
_ = ADD_MINUS_TWO as CInt
128-
_ = ADD_MIXED_WIDTH as CLongLong
129-
_ = ADD_MIXED_SIGN as CLongLong
130-
_ = ADD_UNDERFLOW as CUnsignedInt
131-
_ = ADD_OVERFLOW as CUnsignedInt
132-
133-
_ = SUB_ONE as CInt
134-
_ = SUB_ZERO as CInt
135-
_ = SUB_MINUS_ONE as CInt
136-
_ = SUB_MIXED_WIDTH as CLongLong
137-
_ = SUB_MIXED_SIGN as CUnsignedInt
138-
_ = SUB_UNDERFLOW as CUnsignedInt
139-
_ = SUB_OVERFLOW as CUnsignedInt
140-
141-
_ = MULT_POS as CInt
142-
_ = MULT_NEG as CInt
143-
_ = MULT_MIXED_TYPES as CLongLong
144-
145-
_ = DIVIDE_INTEGRAL as CInt
146-
_ = DIVIDE_NONINTEGRAL as CInt
147-
_ = DIVIDE_MIXED_TYPES as CLongLong
124+
_ = ADD_ZERO as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{16-24=}}
125+
_ = ADD_ONE as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{15-23=}}
126+
_ = ADD_TWO as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{15-23=}}
127+
_ = ADD_MINUS_TWO as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{21-29=}}
128+
_ = ADD_MIXED_WIDTH as CLongLong // expected-warning {{redundant cast to 'CLongLong' (aka 'Int64') has no effect}} {{23-36=}}
129+
_ = ADD_MIXED_SIGN as CLongLong // expected-warning {{redundant cast to 'CLongLong' (aka 'Int64') has no effect}} {{22-35=}}
130+
_ = ADD_UNDERFLOW as CUnsignedInt // expected-warning {{redundant cast to 'CUnsignedInt' (aka 'UInt32') has no effect}} {{21-37=}}
131+
_ = ADD_OVERFLOW as CUnsignedInt // expected-warning {{redundant cast to 'CUnsignedInt' (aka 'UInt32') has no effect}} {{20-36=}}
132+
133+
_ = SUB_ONE as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{15-23=}}
134+
_ = SUB_ZERO as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{16-24=}}
135+
_ = SUB_MINUS_ONE as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{21-29=}}
136+
_ = SUB_MIXED_WIDTH as CLongLong // expected-warning {{redundant cast to 'CLongLong' (aka 'Int64') has no effect}} {{23-36=}}
137+
_ = SUB_MIXED_SIGN as CUnsignedInt // expected-warning {{redundant cast to 'CUnsignedInt' (aka 'UInt32') has no effect}} {{22-38=}}
138+
_ = SUB_UNDERFLOW as CUnsignedInt // expected-warning {{redundant cast to 'CUnsignedInt' (aka 'UInt32') has no effect}} {{21-37=}}
139+
_ = SUB_OVERFLOW as CUnsignedInt // expected-warning {{redundant cast to 'CUnsignedInt' (aka 'UInt32') has no effect}} {{20-36=}}
140+
141+
_ = MULT_POS as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{16-24=}}
142+
_ = MULT_NEG as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{16-24=}}
143+
_ = MULT_MIXED_TYPES as CLongLong // expected-warning {{redundant cast to 'CLongLong' (aka 'Int64') has no effect}} {{24-37=}}
144+
145+
_ = DIVIDE_INTEGRAL as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{23-31=}}
146+
_ = DIVIDE_NONINTEGRAL as CInt // expected-warning {{redundant cast to 'CInt' (aka 'Int32') has no effect}} {{26-34=}}
147+
_ = DIVIDE_MIXED_TYPES as CLongLong // expected-warning {{redundant cast to 'CLongLong' (aka 'Int64') has no effect}} {{26-39=}}
148148
_ = DIVIDE_INVALID // expected-error {{use of unresolved identifier 'DIVIDE_INVALID'}}
149149
}
150150

test/ClangImporter/objc_bridging.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ extension Set {
2626
}
2727

2828
func foo() {
29-
_ = NSStringToNSString as (String?) -> String?
29+
_ = NSStringToNSString as (String?) -> String? // expected-warning {{redundant cast to '(String?) -> String?' has no effect}} {{27-51=}}
3030
_ = DummyClass().nsstringProperty.onlyOnString() as String
3131

32-
_ = BOOLtoBOOL as (Bool) -> Bool
32+
_ = BOOLtoBOOL as (Bool) -> Bool // expected-warning {{redundant cast to '(Bool) -> Bool' has no effect}} {{19-37=}}
3333
_ = DummyClass().boolProperty.onlyOnBool() as Bool
3434

35-
_ = arrayToArray as (Array<Any>?) -> (Array<Any>?)
35+
_ = arrayToArray as (Array<Any>?) -> (Array<Any>?) // expected-warning {{redundant cast to '(Array<Any>?) -> (Array<Any>?)' has no effect}} {{21-55=}}
3636
DummyClass().arrayProperty.onlyOnArray()
3737

38-
_ = dictToDict as (Dictionary<AnyHashable, Any>?) -> Dictionary<AnyHashable, Any>?
38+
_ = dictToDict as (Dictionary<AnyHashable, Any>?) -> Dictionary<AnyHashable, Any>? // expected-warning {{redundant cast to '(Dictionary<AnyHashable, Any>?) -> Dictionary<AnyHashable, Any>?' has no effect}} {{18-86=}}
3939

4040
DummyClass().dictProperty.onlyOnDictionary()
4141

42-
_ = setToSet as (Set<AnyHashable>?) -> Set<AnyHashable>?
42+
_ = setToSet as (Set<AnyHashable>?) -> Set<AnyHashable>? // expected-warning {{redundant cast to '(Set<AnyHashable>?) -> Set<AnyHashable>?' has no effect}} {{16-60=}}
4343
DummyClass().setProperty.onlyOnSet()
4444
}
4545

0 commit comments

Comments
 (0)