Skip to content

Commit 9c80b23

Browse files
author
Greg Parker
committed
[stdlib] Make StdlibUnittest nullability-agnostic for ObjC runtime functions.
1 parent b8fda57 commit 9c80b23

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ func _childProcess() {
629629

630630
#if _runtime(_ObjC)
631631
objc_setUncaughtExceptionHandler {
632-
let exception = $0! as AnyObject
632+
let exception = ($0 as Optional)! as AnyObject
633633
var stderr = _Stderr()
634634
let maybeNSException =
635635
unsafeBitCast(exception, to: _StdlibUnittestNSException.self)

stdlib/private/StdlibUnittestFoundationExtras/StdlibUnittestFoundationExtras.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ public func withOverriddenLocaleCurrentLocale<Result>(
2727
_ temporaryLocale: NSLocale,
2828
_ body: () -> Result
2929
) -> Result {
30-
let oldMethod = class_getClassMethod(
31-
NSLocale.self, #selector(getter: NSLocale.current))
32-
precondition(oldMethod != nil, "could not find +[Locale currentLocale]")
30+
guard let oldMethod = class_getClassMethod(
31+
NSLocale.self, #selector(getter: NSLocale.current)) as Optional
32+
else {
33+
_preconditionFailure("could not find +[Locale currentLocale]")
34+
}
3335

34-
let newMethod = class_getClassMethod(
35-
NSLocale.self, #selector(NSLocale._swiftUnittest_currentLocale))
36-
precondition(newMethod != nil, "could not find +[Locale _swiftUnittest_currentLocale]")
36+
guard let newMethod = class_getClassMethod(
37+
NSLocale.self, #selector(NSLocale._swiftUnittest_currentLocale)) as Optional
38+
else {
39+
_preconditionFailure("could not find +[Locale _swiftUnittest_currentLocale]")
40+
}
3741

3842
precondition(_temporaryLocaleCurrentLocale == nil,
3943
"nested calls to withOverriddenLocaleCurrentLocale are not supported")

0 commit comments

Comments
 (0)