Two Closure Capture Lists Produce Compiler Error

Originator:sethfri
Number:rdar://19373086 Date Originated:01/05/2015
Status:Open Resolved:No
Product:Developer Tools Product Version:Xcode 6.1.1
Classification:Serious Bug Reproducible:Always
 
Summary:
I have a property that is of type LocationManagerDelegate. LocationManagerDelegate subclasses NSObject and implements the CLLocationManagerDelegate protocol. The class allows me to set blocks for various callbacks that the class implements under the hood, like `locationManager:didChangeAuthorizationStatus:`. I have the following code for my property:

lazy var locationManagerDelegate: LocationManagerDelegate = {
        let locationManagerDelegate = LocationManagerDelegate()

          locationManagerDelegate.locationManagerDidChangeAuthorizationStatus = {
            [unowned self] manager, status in
            switch status {
            case .Denied, .Restricted:
                NSLog("Location Access Denied")
                // Handle this scenario
            default:
                self.startMonitoring()
            }
        }
        
        locationManagerDelegate.locationManagerDidFailWithError = {
            manager, error in
            NSLog("Location Manager Failure: %@", error.description)
        }
        
        locationManagerDelegate.locationManagerDidEnterRegion = {
            [unowned self] manager, region in
            let alertController = UIAlertController(title: "Reminder", message: "You are 2 stops away from your requested stop", preferredStyle: .Alert)
            let okAlertAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
            
            alertController.addAction(okAlertAction)
            
            self.presentViewController(alertController, animated: true, completion: nil)
            
            manager.stopMonitoringForRegion(region)
        }
        
        locationManagerDelegate.locationManagerMonitoringDidFailForRegionWithError = {
            manager, region, error in
            NSLog("Location Manager Monitoring Failure: %@", error.description)
        }
        
        return locationManagerDelegate
    }()

You'll notice that I use [unowned self] in two of the closures to avoid creating strong reference cycles. (The locationManagerDelegate holds strong references to the closures which would then hold strong references to self). When I include just one [unowned self] (in either closure), everything compiles fine. However, when I include both, I get the attached compiler error.

Steps to Reproduce:
1. Create a class, A, that has two closure properties
2. In other class, B, create a property of type A, and set initial values for the closure properties.
3. In those initial values, use self to call some other instance methods in B, and use [unowned self] in both closures to avoid creating strong reference cycles
4. The application won't compile

Expected Results:
The application should compile with two closure capture lists.

Actual Results:
The application does not compile with two closure capture lists.

Version:
Xcode 6.1.1, OS X 10.10.1

Notes:


Configuration:


Attachments:
'Screen Shot 2015-01-05 at 3.36.29 AM.png' and 'Screen Shot 2015-01-05 at 3.36.37 AM.png' were successfully uploaded.

Comments

Apple Developer Relations

Please provide a simple sample project showing this issue.

(01/14/2015)

My Reply

Any update on this? This is currently preventing an app from making it onto the App Store.

(02/09/2015)

My Reply

Attached

(01/16/2015)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!