Files
swift-mirror/test/DebugInfo/Errors.swift
Adrian Prantl d50448a55f Represent Swift errors as DW_TAG_thrown_type in DWARF
This allows the debugger to display them alongside the function's
return value when finish-ing a function.

rdar://problem/29481673
2017-04-27 09:45:54 -07:00

37 lines
1.3 KiB
Swift

// 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 -> ())) {}