Skip to content

Commit 51a3de8

Browse files
authored
Merge pull request #68977 from kubamracek/embedded-typed-throws
[embedded] Add a embedded Swift + typed throw test showcasing that we avoid existentials
2 parents b9150ab + 2b90200 commit 51a3de8

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

test/embedded/throw-typed.swift

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -enable-experimental-feature Embedded -enable-experimental-feature TypedThrows -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
2+
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -O -enable-experimental-feature Embedded -enable-experimental-feature TypedThrows -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
3+
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -Osize -enable-experimental-feature Embedded -enable-experimental-feature TypedThrows -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
4+
5+
// REQUIRES: executable_test
6+
// REQUIRES: optimized_stdlib
7+
// REQUIRES: VENDOR=apple
8+
// REQUIRES: OS=macosx
9+
10+
public enum MyError : Error, Equatable {
11+
case a
12+
case b
13+
case c(Int)
14+
}
15+
16+
extension Int : Error {}
17+
18+
public func throwing(which: Int) throws(MyError) -> Int {
19+
if which == 0 {
20+
throw MyError.a
21+
} else if which == 1 {
22+
throw MyError.b
23+
} else if which == 2 {
24+
throw MyError.c(42)
25+
}
26+
27+
return 123
28+
}
29+
30+
public func throwing2() throws(Int) {
31+
throw 42
32+
}
33+
34+
public func catching() {
35+
do {
36+
try throwing(which: 0)
37+
} catch let e as MyError {
38+
print(e == .a ? "OK1" : "???")
39+
}
40+
41+
do {
42+
try throwing(which: 1)
43+
} catch let e as MyError where e == .b {
44+
print(e == .b ? "OK2" : "???")
45+
} catch {
46+
print("???")
47+
}
48+
49+
do {
50+
try throwing(which: 2)
51+
} catch let e as MyError where e == .b {
52+
print("???")
53+
} catch {
54+
print("OK3")
55+
}
56+
57+
do {
58+
try throwing(which: 2)
59+
} catch let e as MyError {
60+
if case .c(let n) = e {
61+
print(n == 42 ? "OK4" : "???")
62+
} else {
63+
print("???")
64+
}
65+
} catch {
66+
print("???")
67+
}
68+
69+
do {
70+
try throwing(which: 3)
71+
print("OK5")
72+
} catch {
73+
print("???")
74+
}
75+
76+
do {
77+
try throwing2()
78+
} catch {
79+
print(error == 42 ? "OK6" : "???")
80+
}
81+
}
82+
83+
@main
84+
struct Main {
85+
static func main() {
86+
catching()
87+
}
88+
}
89+
90+
// CHECK: OK1
91+
// CHECK: OK2
92+
// CHECK: OK3
93+
// CHECK: OK4
94+
// CHECK: OK5
95+
// CHECK: OK6
96+
97+
// CHECK-NOT: ???

0 commit comments

Comments
 (0)