File tree Expand file tree Collapse file tree 1 file changed +97
-0
lines changed Expand file tree Collapse file tree 1 file changed +97
-0
lines changed Original file line number Diff line number Diff line change
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: ???
You can’t perform that action at this time.
0 commit comments