PhoneNumberKit icon indicating copy to clipboard operation
PhoneNumberKit copied to clipboard

PhoneNumberKit UnsafeMutableBufferPointer ans @Sendable errors

Open kallah94 opened this issue 1 year ago • 1 comments

New Issue Checklist

  • [x ] Updated PhoneNumberKit to the latest version
  • [ ] Phone number formatted correctly on JavaScript version
  • [x ] I searched for existing GitHub issues
  • [ ] 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

Flutter project run for iOS Flutter dependencies: _flutterfire_internals 1.3.40 (1.3.43 available) cloud_firestore 5.2.1 (5.4.2 available) cloud_firestore_platform_interface 6.3.1 (6.4.2 available) cloud_firestore_web 4.1.1 (4.3.1 available) collection 1.18.0 (1.19.0 available) firebase_auth 5.1.4 (5.3.0 available) firebase_auth_platform_interface 7.4.3 (7.4.6 available) firebase_auth_web 5.12.5 (5.13.1 available) firebase_core 3.3.0 (3.5.0 available) firebase_core_platform_interface 5.2.0 (5.3.0 available) firebase_core_web 2.17.4 (2.18.1 available) firebase_storage 12.1.3 (12.3.1 available) firebase_storage_platform_interface 5.1.27 (5.1.30 available) firebase_storage_web 3.9.12 (3.10.1 available) http_parser 4.0.2 (4.1.0 available) js 0.6.7 (0.7.1 available) leak_tracker 10.0.5 (10.0.7 available) leak_tracker_flutter_testing 3.0.5 (3.0.8 available) material_color_utilities 0.11.1 (0.12.0 available) meta 1.15.0 (1.16.0 available) shared_preferences_android 2.3.1 (2.3.2 available) string_scanner 1.2.0 (1.3.0 available) test_api 0.7.2 (0.7.3 available) vm_service 14.2.4 (14.2.5 available) web 0.5.1 (1.0.0 available)

Simulator on Iphone 16 and iOS 18

CFBundleDevelopmentRegion ${PODS_DEVELOPMENT_LANGUAGE} CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier ${PRODUCT_BUNDLE_IDENTIFIER} CFBundleInfoDictionaryVersion 6.0 CFBundleName ${PRODUCT_NAME} CFBundlePackageType FMWK CFBundleShortVersionString 4.0.0 CFBundleSignature ???? CFBundleVersion ${CURRENT_PROJECT_VERSION} NSPrincipalClass ##### Expected result Build ios app for simulator ##### Actual result

arseManager.swift:112:21: warning: capture of 'buffer' with non-sendable type 'UnsafeMutableBufferPointer<PhoneNumber>' in a @Sendable closure; this is an error in the Swift 6 language mode buffer.baseAddress!.advanced(by: index).initialize(to: phoneNumber) ^ Swift.UnsafeMutableBufferPointer:1:23: note: generic struct 'UnsafeMutableBufferPointer' does not conform to the 'Sendable' protocol @frozen public struct UnsafeMutableBufferPointer<Element> : Copyable where Element : ~Copyable {

ParseManager.swift:112:21: warning: capture of 'buffer' with non-sendable type 'UnsafeMutableBufferPointer<PhoneNumber>' in a @Sendable closure; this is an error in the Swift 6 language mode buffer.baseAddress!.advanced(by: index).initialize(to: phoneNumber) ^ Swift.UnsafeMutableBufferPointer:1:23: note: generic struct 'UnsafeMutableBufferPointer' does not conform to the 'Sendable' protocol

SwiftLibphonenumberPlugin.swift:7:25: note: cannot use module 'PhoneNumberKit' as a type let phoneNumberKit: PhoneNumberKit = PhoneNumberKit() @frozen public struct UnsafeMutableBufferPointer<Element> : Copyable where Element : ~Copyable {

Environment

kallah94 avatar Sep 22 '24 03:09 kallah94

The same is happening in Xcode 16.1 Screenshot 2024-10-15 at 3 57 40 PM

AhmedRagabIssa avatar Oct 15 '24 12:10 AhmedRagabIssa

You can workaround this by redeclaring the buffer as nonisolated(unsafe).

var multiParseArray = [PhoneNumber](unsafeUninitializedCapacity: numberStrings.count) { buffer, initializedCount in
            nonisolated(unsafe) let buffer = buffer  // Redeclaration here
            DispatchQueue.concurrentPerform(iterations: numberStrings.count) { [buffer] index in
                let numberString = numberStrings[index]
                do {
                    let phoneNumber = try self.parse(numberString, withRegion: region, ignoreType: ignoreType)
                    buffer.baseAddress!.advanced(by: index).initialize(to: phoneNumber)
                } catch {
                    buffer.baseAddress!.advanced(by: index).initialize(to: PhoneNumber.notPhoneNumber())
                    hasError = true
                }
            }
            initializedCount = numberStrings.count
        }

Jean-Daniel avatar Oct 29 '24 08:10 Jean-Daniel

This issue was already addressed and fixed.

bguidolim avatar Oct 29 '24 08:10 bguidolim