Hmm... I just tried it in a playground, and it works:
struct DistortedNoise<Source, Displacement> {
let source:Source,
displacement:Displacement
init(source:Source, displacement:Displacement)
{
self.source = source
self.displacement = displacement
}
}
extension DistortedNoise where Source == Displacement {
init(source:Source)
{
self.source = source
self.displacement = source
}
}
let foo = DistortedNoise(source: 1) // DistortedNoise<Int, Int>
foo.source // 1
foo.displacement // 1
That's with Xcode 9b2, using the default Xcode 9.0 toolchain. With Xcode 8.3.3
and its default toolchain, the `let foo = ...` line outputs
"__lldb_expr_2.DistortedNoise<Int, Int>" instead of just "DistortedNoise<Int,
Int>", but that's just a more... I think the word is "qualified"... name for
the same thing.
- Dave Sweeris
> On Jul 8, 2017, at 9:39 PM, Zhao Xin <[email protected]> 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
> <[email protected] <mailto:[email protected]>> 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
> > <[email protected] <mailto:[email protected]>> 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
> > [email protected] <mailto:[email protected]>
> > https://lists.swift.org/mailman/listinfo/swift-users
> > <https://lists.swift.org/mailman/listinfo/swift-users>
> _______________________________________________
> swift-users mailing list
> [email protected] <mailto:[email protected]>
> https://lists.swift.org/mailman/listinfo/swift-users
> <https://lists.swift.org/mailman/listinfo/swift-users>
>
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users