[swift-evolution] Pitch: Allow generic functions to fulfill non-generic protocol requirements

David Sweeris davesweeris at mac.com
Wed May 24 19:21:17 CDT 2017


> On May 24, 2017, at 5:11 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
> On Wed, May 24, 2017 at 3:32 PM, David Sweeris via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> So, I’m working on a type, and would like to make it conform to `ExpressibleByArrayLiteral`. The thing is, I don’t actually care what type `Element` is as long as it conforms to `FixedWidthInteger` and `UnsignedInteger`. I tried writing this:
>   public init <U: FixedWidthInteger & UnsignedInteger> (arrayLiteral elements: U...) { … }
> But Xcode says my type doesn’t conform to `ExpressibleByArrayLiteral` unless I add an init that takes a concrete type:
>   public init(arrayLiteral elements: UInt...) { … }
> 
> Does anyone else think the generic init should to be able to satisfy `ExpressibleByArrayLiteral` (especially since `UInt` meets the conformance requirements)?
> 
> Your type needs to be generic.

It already is… I just don’t want to restrict it to being initialized from array literals containing that same generic type.

- Dave Sweeris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170524/111c2047/attachment.html>


More information about the swift-evolution mailing list