[swift-users] Superclass constraint cannot depend on type parameter

Slava Pestov spestov at apple.com
Thu Mar 17 12:01:32 CDT 2016


Hi Jon,

You are right that this is a limitation of the current implementation in Swift 2.2. I may have fixed this recently in master:

https://github.com/apple/swift/commit/3aacf5d805768527b59d24e6da2a03911b3dd5b0 <https://github.com/apple/swift/commit/3aacf5d805768527b59d24e6da2a03911b3dd5b0>

It would be great if you could try the latest compiler with your code.

Slava

> On Mar 9, 2016, at 12:48 PM, Jon Shier via swift-users <swift-users at swift.org> wrote:
> 
> Swifters:
> 	I just encountered the error “Superclass constraint ‘RepeatableNetworkOperation<U>’ cannot depend on a type parameter” on this definition:
> 
> class RepeatedNetworkOperation<T, U where U: Decodable, U == U.DecodedType, U: Repeatable, T: RepeatableNetworkOperation<U>>: RepeatedOperation<T> { … }
> 
> where the relevant other classes are defined as:
> 
> class InterruptibleNetworkOperation<T: Decodable where T == T.DecodedType>: GroupOperation { … }
> class RepeatedOperation<T where T: NSOperation>: GroupOperation { … }
> class RepeatableNetworkOperation<T where T: Decodable, T == T.DecodedType, T: Repeatable>: InterruptibleNetworkOperation<T>, Repeatable { … }
> 
> I understand the error, but am I correct in thinking this is just a limitation of Swift’s current type and/or generics systems? I’m not a language theorist, but it seems perfectly reasonable that something like this should work. If it is just a limitation and not something I’m doing wrong, are there any suggestions for a workaround? The class I’m trying to write would really clean up my code.
> 
> 
> Jon
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160317/31b1d06f/attachment.html>


More information about the swift-users mailing list