google / google/promises

`ObjCPromise` initializer fails for arrays in Swift 6.4

Open
#245 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Objective-C
Stars
3.8k
Forks
316
PR merge metrics
No merged PRs in 30d

Description

The following initializer fails its precondition under Swift 6.4 when `T` is an array:
```
public init(_ objCPromise: ObjCPromise) {
guard let objCPromise = objCPromise as? ObjCPromise else {
preconditionFailure("Cannot cast \(T.self) to \(AnyObject.self)")
}
self.objCPromise = objCPromise
}
```
The function to get an `ObjCPromise` from a `Promise` (relying on the same `Array` → `AnyObject` cast) does too.

Replacing the current cast with an `unsafeBitCast` seems to fix the issue in both cases, but I haven't yet tested it thoroughly enough to be certain.

Contributor guide

Open the contributing guide

Research direction

Start by locating the ObjCPromise initializer shown in the report and the function that converts a Promise to an ObjCPromise. Reproduce both failures with an array type under Swift 6.4, then verify that the completed change no longer triggers the precondition in either path.

Written by the indexing model from the issue text.

Assessment

Tech stack
objective-c, swift
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.