File tree Expand file tree Collapse file tree 1 file changed +95
-0
lines changed Expand file tree Collapse file tree 1 file changed +95
-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
+
3
+ // REQUIRES: executable_test
4
+ // REQUIRES: optimized_stdlib
5
+ // REQUIRES: VENDOR=apple
6
+ // REQUIRES: OS=macosx
7
+
8
+ public enum MyError : Error , Equatable {
9
+ case a
10
+ case b
11
+ case c( Int )
12
+ }
13
+
14
+ extension Int : Error { }
15
+
16
+ public func throwing( which: Int ) throws ( MyError) -> Int {
17
+ if which == 0 {
18
+ throw MyError . a
19
+ } else if which == 1 {
20
+ throw MyError . b
21
+ } else if which == 2 {
22
+ throw MyError . c ( 42 )
23
+ }
24
+
25
+ return 123
26
+ }
27
+
28
+ public func throwing2( ) throws ( Int) {
29
+ throw 42
30
+ }
31
+
32
+ public func catching( ) {
33
+ do {
34
+ try throwing ( which: 0 )
35
+ } catch let e as MyError {
36
+ print ( e == . a ? " OK1 " : " ??? " )
37
+ }
38
+
39
+ do {
40
+ try throwing ( which: 1 )
41
+ } catch let e as MyError where e == . b {
42
+ print ( e == . b ? " OK2 " : " ??? " )
43
+ } catch {
44
+ print ( " ??? " )
45
+ }
46
+
47
+ do {
48
+ try throwing ( which: 2 )
49
+ } catch let e as MyError where e == . b {
50
+ print ( " ??? " )
51
+ } catch {
52
+ print ( " OK3 " )
53
+ }
54
+
55
+ do {
56
+ try throwing ( which: 2 )
57
+ } catch let e as MyError {
58
+ if case . c( let n) = e {
59
+ print ( n == 42 ? " OK4 " : " ??? " )
60
+ } else {
61
+ print ( " ??? " )
62
+ }
63
+ } catch {
64
+ print ( " ??? " )
65
+ }
66
+
67
+ do {
68
+ try throwing ( which: 3 )
69
+ print ( " OK5 " )
70
+ } catch {
71
+ print ( " ??? " )
72
+ }
73
+
74
+ do {
75
+ try throwing2 ( )
76
+ } catch {
77
+ print ( error == 42 ? " OK6 " : " ??? " )
78
+ }
79
+ }
80
+
81
+ @main
82
+ struct Main {
83
+ static func main( ) {
84
+ catching ( )
85
+ }
86
+ }
87
+
88
+ // CHECK: OK1
89
+ // CHECK: OK2
90
+ // CHECK: OK3
91
+ // CHECK: OK4
92
+ // CHECK: OK5
93
+ // CHECK: OK6
94
+
95
+ // CHECK-NOT: ???
You can’t perform that action at this time.
0 commit comments