[swift-users] Filling two type parameters with the same type

David Sweeris davesweeris at mac.com
Sun Jul 9 00:20:14 CDT 2017


Oh, I hate that error! If there was ever a time I've wanted to have a conversation with the compiler... "yes, mr compiler, I know the same type requirement makes them equivalent; that's why I wrote it! Please compile anyway."

Which version of the compiler/language are you using?

Sent from my iPhone

> On Jul 8, 2017, at 21:39, Zhao Xin <owenzx at gmail.com> wrote:
> 
> No, David, it is now allowed.  "error: same-type requirement makes generic parameters 'Source' and 'Displacement' equivalent".
> 
> Zhao Xin
> 
>> On Sun, Jul 9, 2017 at 12:35 PM, David Sweeris via swift-users <swift-users at swift.org> wrote:
>> You could try putting that init in an extension "where Source == Displacement"
>> 
>> > On Jul 8, 2017, at 21:06, Taylor Swift via swift-users <swift-users at swift.org> wrote:
>> >
>> > I have a type like
>> >
>> > struct DistortedNoise<Source, Displacement> where Source:Noise, Displacement:Noise
>> > {
>> >     let source:Source,
>> >         displacement:Displacement
>> >
>> >     init(source:Source, displacement:Displacement)
>> >     {
>> >         self.source       = source
>> >         self.displacement = displacement
>> >     }
>> >
>> >     init(source:Source)
>> >     {
>> >         self.source       = source
>> >         self.displacement = source
>> >     }
>> > }
>> >
>> > and I get the error
>> >
>> > Compile Swift Module 'Noise' (5 sources)
>> > /home/taylor/noise/sources/noise/noise.swift:576:29: error: 'Source' is not convertible to 'Displacement'
>> >         self.displacement = source
>> >                             ^~~~~~
>> >
>> > How do I tell Swift that I want the same type fulfilling both Source and Displacement?
>> >
>> > _______________________________________________
>> > swift-users mailing list
>> > swift-users at swift.org
>> > https://lists.swift.org/mailman/listinfo/swift-users
>> _______________________________________________
>> 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/20170708/456d8e35/attachment.html>


More information about the swift-users mailing list