Skip to content

Commit e1f11d2

Browse files
committed
Add a negative test for generic binding checks
1 parent 1457e4d commit e1f11d2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test/Constraints/suspicious_bit_casts.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class B: A {}
1616
class C<T> {}
1717
class D: C<Int> {}
1818

19+
class N<T> {}
20+
1921
func castAToB(a: A) -> B {
2022
// expected-warning@+1{{'unsafeBitCast' from 'A' to 'B' can be replaced with 'unsafeDowncast'}} {{7-20=unsafeDowncast}}
2123
_ = unsafeBitCast(a, to: B.self)
@@ -29,6 +31,10 @@ func castCToD<T>(c: C<T>) -> D {
2931
return unsafeBitCast(c, to: D.self)
3032
}
3133

34+
func castNToD<T>(n: N<T>) -> D {
35+
return unsafeBitCast(n, to: D.self) // CHECK-NOT: warning
36+
}
37+
3238
func castDToC<T>(d: D) -> (C<T>, C<Int>) {
3339
let a = unsafeBitCast(d, to: C<T>.self) // not necessarily a no-op if T != Int
3440
// expected-warning@+1{{'unsafeBitCast' from 'D' to 'C<Int>' is unnecessary}}{{11-25=}}{{26-44=}}

0 commit comments

Comments
 (0)