> On Jun 2, 2017, at 3:08 AM, Zaid Daghestani via swift-evolution 
> <[email protected]> wrote:
> 
> Wow, you’re right. Look like this is a bug? The issue shows up in class 
> definitions, not protocol definitions.        
> 
> This works:
> 
> protocol Selfie {
>     static func retOne() -> Self
>     static func retMany() -> Array<Self>
>     static func retTuple() -> (Self, Int)
> }
> 
> This doesn’t work:
> 
> class Selfie {
>     required init() {}
>     // Compiles
>     static func retOne() -> Self {return self.init()}
>     // Doesn't Compile
>     static func retMany() -> Array<Self> { return [] }
>     // Doesn't Compile
>     static func retTuple() -> (Self, Int) { return (self.init(), 0) }
>     
> }
> 
> So Self in non-nominal types with class methods end up with the compiler 
> error:
> 
> Error: 'Self' is only available in a protocol or as the result of a method in 
> a class; did you mean ’Selfie’?
> 
> Can we get confirmation from anyone?

Yes, `Self` in classes is currently restricted to being the return type of a 
method. This could eventually be generalized to allow `Self` in any covariant 
position within a class method type, and in fact SE-0068 
(https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md)
 was accepted to allow this generalization, but we haven't done the 
implementation work to enable it yet.

-Joe
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to