Swift does not allow optional containing Self as parameter

Originator:wagner
Number:rdar://20398997 Date Originated:02-Apr-2015 03:24 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Swift 1.2 b4
Classification:Serious Bug Reproducible:Not Applicable
 
Why is a closure taking Self allowed as a parameter in a non-final class, so long as it isn't optional?

Developer forums topic: https://devforums.apple.com/message/1119632#1119632

Allowed:
=======
 
protocol MyProto
{
    func reload( completionHandler: (Self)->() )
}

class MyClass : MyProto
{
    func reload( completionHandler: (MyClass)->() )
    {
        // Do work
        completionHandler( self )
    }
}
 
Forbidden:
=========

protocol MyProto
{
    func reload( completionHandler: ((Self)->())? )
}

class MyClass : MyProto
{
    func reload( completionHandler: ((Self)->())? )
    {
        // Do work
        completionHandler?( self )
    }

=========
 
The compiler's error is:
 
error: protocol 'MyProto' requirement 'reload' cannot be satisfied by a non-final class ('MyClass') because it uses 'Self' in a non-parameter, non-result type position

I don't understand that. I am using 'Self' in a parameter type position, just embedded inside an Optional. Is this a bug or is there some reason why this cannot be supported?

Comments


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!