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

Jon Shier jon at jonshier.com
Thu Mar 17 12:42:23 CDT 2016


Slava:
	I won’t be able to test my actual code, as the Operations and Alamofire libraries haven’t been updated for Swift 3 (which I wouldn’t expect), but I’ll try to put together a test cast that is similar and see if it works? When will this change be part of the package I can download for Xcode 7.3?


Jon
> On Mar 17, 2016, at 1:01 PM, Slava Pestov <spestov at apple.com> wrote:
> 
> 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 <mailto: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 <mailto: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/f1e60518/attachment.html>


More information about the swift-users mailing list