-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathErrors.swift
36 lines (30 loc) · 1.3 KB
/
Errors.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
public enum E : Error { case Err }
// Function throws.
public func throwError() throws { throw E.Err }
// CHECK: !DISubprogram(name: "throwError", {{.*}}thrownTypes: ![[THROWN:.*]])
// CHECK: ![[THROWN]] = !{![[ERROR:[0-9]+]]}
// CHECK: ![[ERROR]] = !DICompositeType(tag: DW_TAG_structure_type,
// CHECK-SAME: name: "Error"
// Function rethrows.
public func rethrow(fn : (() throws -> ())) rethrows { try fn() }
// CHECK: !DISubprogram(name: "rethrow", {{.*}}thrownTypes: ![[THROWN:.*]])
public class C {
// Initializer throws.
init() throws { throw E.Err }
// CHECK: !DISubprogram(name: "init", {{.*}}line: [[@LINE-1]],
// CHECK-SAME: thrownTypes: ![[THROWN:.*]])
// Initializer rethrows.
init(fn : (() throws -> ())) rethrows {
// CHECK: !DISubprogram(name: "init", {{.*}}line: [[@LINE-1]],
// CHECK-SAME: thrownTypes: ![[THROWN:.*]])
try fn()
}
}
// Negative tests.
// CHECK: !DISubprogram(name: "returnThrowing",
// CHECK-NOT: thrownTypes:
public func returnThrowing() -> (() throws -> ()) { return throwError }
// CHECK: !DISubprogram(name: "takesThrowing",
// CHECK-NOT: thrownTypes:
public func takesThrowing(fn : (() throws -> ())) {}