Skip to content

Commit bc48b3d

Browse files
committed
stdlib: Use the new failure message method for the "unexpected found nil while unwrapping an optional" failure message.
Advantage: the failure message is now also visible in release builds.
1 parent f8325ad commit bc48b3d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

stdlib/public/core/Optional.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,21 @@ func _diagnoseUnexpectedNilOptional(_filenameStart: Builtin.RawPointer,
302302
_isImplicitUnwrap: Builtin.Int1) {
303303
// Cannot use _preconditionFailure as the file and line info would not be
304304
// printed.
305-
preconditionFailure(
306-
Bool(_isImplicitUnwrap)
307-
? "Unexpectedly found nil while implicitly unwrapping an Optional value"
308-
: "Unexpectedly found nil while unwrapping an Optional value",
309-
file: StaticString(_start: _filenameStart,
310-
utf8CodeUnitCount: _filenameLength,
311-
isASCII: _filenameIsASCII),
312-
line: UInt(_line))
305+
if Bool(_isImplicitUnwrap) {
306+
_preconditionFailure(
307+
"Unexpectedly found nil while implicitly unwrapping an Optional value",
308+
file: StaticString(_start: _filenameStart,
309+
utf8CodeUnitCount: _filenameLength,
310+
isASCII: _filenameIsASCII),
311+
line: UInt(_line))
312+
} else {
313+
_preconditionFailure(
314+
"Unexpectedly found nil while unwrapping an Optional value",
315+
file: StaticString(_start: _filenameStart,
316+
utf8CodeUnitCount: _filenameLength,
317+
isASCII: _filenameIsASCII),
318+
line: UInt(_line))
319+
}
313320
}
314321

315322
extension Optional : Equatable where Wrapped : Equatable {

0 commit comments

Comments
 (0)