Skip to content

Commit 1fa9d96

Browse files
authored
Avoid specialization of unsafeBitCast(_:to:) when getting an error's backtrace. (#414)
It appears the Swift compiler has recently started specializing `unsafeBitCast(_:to:)` more aggressively than before, resulting in a call to that function in `Backtrace.init(forFirstThrowOf:)` crashing because the size of the input error (expected to be an existential box of type `NSError` or `SwiftError`, i.e. actually an object) doesn't match the size of `AnyObject`. This PR explicitly asks the compiler not to specialize `unsafeBitCast(_:to:)` quite so precisely, preserving the intended semantics. (This method is already known to contain non-zero quantities of "wat.") ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 04de85b commit 1fa9d96

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/Testing/SourceAttribution/Backtrace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ extension Backtrace {
220220
/// existential containers with different addresses.
221221
@inline(never)
222222
init?(forFirstThrowOf error: any Error) {
223-
let errorID = ObjectIdentifier(unsafeBitCast(error, to: AnyObject.self))
223+
let errorID = ObjectIdentifier(unsafeBitCast(error as any Error, to: AnyObject.self))
224224
let entry = Self._errorMappingCache.withLock { cache in
225225
cache[errorID]
226226
}

0 commit comments

Comments
 (0)