mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
21 lines
695 B
Swift
21 lines
695 B
Swift
// REQUIRES: objc_interop
|
|
// RUN: %target-swift-frontend -emit-sil -Xllvm -sil-print-debuginfo %s \
|
|
// RUN: -parse-as-library | %FileCheck %s
|
|
import Foundation
|
|
|
|
open class Cache<T> {
|
|
let _negativeCache: NSMutableDictionary = NSMutableDictionary()
|
|
func cachedValue(creationBlock: () throws -> T) throws -> T {
|
|
do {
|
|
let value = try creationBlock()
|
|
return value
|
|
} catch {
|
|
// CHECK: debug_value {{.*}} : $any Error, let, name "error", loc "{{.*}}":[[@LINE-1]]:13, scope [[SCOPE:[0-9]+]]
|
|
// CHECK: alloc_stack $@opened({{.*}}, any Error) Self, loc{{.*}}, scope [[SCOPE]]
|
|
|
|
_negativeCache.setObject(error, forKey: NSNumber(1))
|
|
throw error
|
|
}
|
|
}
|
|
}
|