Skip to content

Commit 49fdf19

Browse files
committed
NCGenerics: add casting test
1 parent 2e01f4e commit 49fdf19

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// RUN: %target-run-simple-swift(-Xfrontend -sil-verify-all -enable-experimental-feature NoncopyableGenerics) | %FileCheck %s
2+
// RUN: %target-run-simple-swift(-O -Xfrontend -sil-verify-all -enable-experimental-feature NoncopyableGenerics) | %FileCheck %s
3+
4+
protocol P {
5+
func speak()
6+
}
7+
8+
extension P {
9+
func speak() { print("hello") }
10+
}
11+
12+
struct Noncopyable: ~Copyable {}
13+
struct Ordinary {}
14+
15+
struct Dog<T: ~Copyable>: Copyable {}
16+
extension Dog: P where T: Copyable {}
17+
18+
enum Cat<Left: ~Copyable, Right: ~Copyable>: Copyable {
19+
case meows
20+
init() { self = .meows }
21+
}
22+
extension Cat: P where Left: Copyable {}
23+
24+
func attemptCall(_ a: Any) {
25+
if let value = a as? P {
26+
value.speak()
27+
return
28+
}
29+
print("failed to cast (attemptCall)")
30+
}
31+
32+
defer { main() }
33+
func main() {
34+
// CHECK: hello
35+
attemptCall(Dog<Ordinary>())
36+
37+
// FIXME: this is NOT suppose to succeed! (rdar://123466649)
38+
// CHECK: hello
39+
attemptCall(Dog<Noncopyable>())
40+
41+
// CHECK: hello
42+
attemptCall(Cat<Ordinary, Noncopyable>())
43+
44+
// FIXME: this is NOT suppose to succeed! (rdar://123466649)
45+
// CHECK: hello
46+
attemptCall(Cat<Noncopyable, Ordinary>())
47+
48+
// FIXME: this should succeeed!!
49+
// CHECK: failed to cast (test_radar124171788)
50+
test_radar124171788(.nothing)
51+
}
52+
53+
// coverage for rdar://124171788
54+
enum Maybe<Wrapped: ~Copyable>: ~Copyable {
55+
case just(Wrapped)
56+
case nothing
57+
}
58+
extension Maybe: Copyable {}
59+
extension Maybe: CustomStringConvertible {
60+
var description: String {
61+
"cast succeeded"
62+
}
63+
}
64+
func test_radar124171788(_ v: Maybe<Int>) {
65+
if let foo = v as? CustomDebugStringConvertible {
66+
print("\(foo.debugDescription)")
67+
return
68+
}
69+
print("failed to cast (test_radar124171788)")
70+
}

0 commit comments

Comments
 (0)