Use of Inherited Protocol as Typealias

In the following code example, I get a "does not conform to protocol" on MyStruct.


protocol OutsideProtocol {
    typealias T: InsideProtocol
}

protocol InsideProtocol { }
protocol InheritingProtocol: InsideProtocol { }

struct MyStruct: OutsideProtocol {
    typealias T = InheritingProtocol
}


This would compile if InheritingProtocol were a struct or class. Is this a known limitation and is there a workaround?

Answered by OOPer in 29115022

It's a known limitation. You can find some threads, searching with "protocol does not conform to protocol".

For example: Re: Extending SequenceType for elements conforming to a protocol(Message) By DaveAbrahams, posted Jun 25 2015


Workarounds depend on what you can accept.

One proposal, make your MyStruct generic:

struct MyStruct<InsideType: InheritingProtocol>: OutsideProtocol {
    typealias T = InsideType
}
Accepted Answer

It's a known limitation. You can find some threads, searching with "protocol does not conform to protocol".

For example: Re: Extending SequenceType for elements conforming to a protocol(Message) By DaveAbrahams, posted Jun 25 2015


Workarounds depend on what you can accept.

One proposal, make your MyStruct generic:

struct MyStruct<InsideType: InheritingProtocol>: OutsideProtocol {
    typealias T = InsideType
}
Use of Inherited Protocol as Typealias
 
 
Q