[swift-users] Redundant superclass constraint
Slava Pestov
spestov at apple.com
Wed Oct 25 15:09:46 CDT 2017
Hi Phil,
I think the warning is bogus in this case. Do you mind filing a bug?
Slava
> On Oct 24, 2017, at 11:00 PM, Phil Kirby via swift-users <swift-users at swift.org> wrote:
>
> Original StackOverflow post:
>
> https://stackoverflow.com/questions/46924554/redundant-superclass-constraint-in-swift-4 <https://stackoverflow.com/questions/46924554/redundant-superclass-constraint-in-swift-4>
>
> <https://stackoverflow.com/questions/46924554/redundant-superclass-constraint-in-swift-4#>
> I'm getting a Redundant superclass constraint... warning in swift4: (paste in a playground)
>
> import CoreData
>
> class Item : NSManagedObject {}
>
> protocol DataSourceProtocol {
> associatedtype DataSourceItem : NSManagedObject
> }
>
> protocol DataSourceProtocolProvider : class { }
>
> extension DataSourceProtocolProvider {
> func createDataSource<T: DataSourceProtocol>(dataSource: T)
> where T.DataSourceItem == Item {
> }
> }
> On the createDataSource<T: DataSourceProtocol> declaration I get the following warning:
>
> Redundant superclass constraint 'T.DataSourceItem' : 'NSManagedObject'
>
> I thought that you could specify that an associatedtype could be used with the == operator to constrain the associatedtype to a specific type. I want to have a func createDataSource<T: DataSourceProtocol>(dataSource:T) where the DataSourceItem is an Item.
>
> If I replace the == operator with : then the warning goes away:
>
> extension DataSourceProtocolProvider {
> func createDataSource<T: DataSourceProtocol>(dataSource: T)
> where T.DataSourceItem : Item {
> }
> }
> This happens to be a completely different context now. This constraint specifies that I want to have a func createDataSource<T: DataSourceProtocol>(dataSource:T) where the DataSourceItem is a subclass of Item. Which isn't the same thing as DataSourceItem is an Item object. Also, the code runs fine with == so am I just not understanding how constraints work?
>
>
> _______________________________________________
> 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/20171025/ea1fc04c/attachment.html>
More information about the swift-users
mailing list