PhoneNumberKit
PhoneNumberKit copied to clipboard
Data race runtime issue + Capture of 'buffer' with non-sendable type Warning
New Issue Checklist
- [x] Updated PhoneNumberKit to the latest version
- [x] Phone number formatted correctly on JavaScript version
- [x] I searched for existing GitHub issues
- [x] I am aware that this library is not responsible of adding/removing/changing phone number formats and any request should be done at libphonenumber repo
Steps to reproduce
The following code in a concurrent background thread produces a data race when the Thread Sanitizer is enabled:
struct ContactData {
let number: [String]
}
let utility = PhoneNumberUtility()
let dataArray: [ContactData] = [...]
for item in dataArray {
utility.parse(item.numbers)
}
Expected result
No warning, nor data race.
Actual result
- There is a data race accessing the
hasErrorproperty:
Data race in closure #1 @Sendable (Swift.Int) -> () in closure #1 (inout Swift.UnsafeMutableBufferPointer<PhoneNumberKit.PhoneNumber>, inout Swift.Int) -> () in PhoneNumberKit.ParseManager.parseMultiple(_: Swift.Array<Swift.String>, withRegion: Swift.String, ignoreType: Swift.Bool, shouldReturnFailedEmptyNumbers: Swift.Bool) -> Swift.Array<PhoneNumberKit.PhoneNumber>
2, Opening the Project in Xcode 16.1 on master, shows a warning on line 112:
Capture of 'buffer' with non-sendable type 'UnsafeMutableBufferPointer<PhoneNumber>' in a `@Sendable` closure; this is an error in the Swift 6 language mode
Environment
Xcode 16.1 + SPM (v4.0.1 / master)
Hey @bguidolim, let me know if there is something I missed on this 🙏
Fixed with #826
Thanks for your contribution @aiFigueiredo