Skip to content

Commit c77a8f9

Browse files
committed
80534: SE-0217 Introducing the !! "Unwrap or Die" operator (partial, compiler work needed too)
1 parent ac80f9b commit c77a8f9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Source/Operators.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,18 @@
99
#elseif COCOA
1010
__throw NSException(name: "Cannot force-unwrap reference", reason: "Cannot force-unwrap reference", userInfo: nil)
1111
#endif
12+
}
13+
14+
//
15+
//
16+
// CAUTION: Magic function name.
17+
// The compiler will use UnwrapOrDie<T> to provide the `!!` Unwrap-or-die operator (SE-0217)
18+
//
19+
//
20+
21+
public func UnwrapOrDie<T>(_ val: T?, _ error: NativeString) -> T {
22+
if let val = val {
23+
return val
24+
}
25+
throw Exception(error)
1226
}

0 commit comments

Comments
 (0)