[swift-dev] SubstitutionMap questions

Karl razielim at gmail.com
Sun Jan 1 23:49:10 CST 2017


Hey there,

I filed this bug. Sorry that I mentioned it was to do with the TODO - I tried to trace it back myself, found that the substitution map was giving a null for the same-type requirement (and that “getDependentTypes()” explicitly skips them), and assumed that was the reason. Try as I might, I couldn’t figure out how to resolve it so I assumed I was lacking requisite knowledge of substitution maps to fix it (which turns out to be correct - thanks for the great explanation, Slava!)


> On 31 Dec 2016, at 01:09, Slava Pestov via swift-dev <swift-dev at swift.org> wrote:
> 
> extension Array where Element == S, Element : P {
>   func doSomething() {}
> }
> 
> The ‘Element : P’ requirement is redundant and is dropped from the signature, and ‘doSomething’ has the same exact type as if we had written:
> 
> extension Array where Element == S {
>   func doSomething() {}
> }

What if the S: P conformance is conditional or introduced by another module? The presence same-type constraint isn’t enough to say that S will _never_ conform to P (if it doesn’t already conform).


extension S: P where S.SomeType == Int, S.AnotherType: Collection, S.AnotherType.Index == SomeType {
 // conform to P
}

extension Array where Element == S, S.SomeType == Int, S.AnotherType: Collection, // …etc

vs

extension Array where Element == S, S: P

- Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20170102/2900a571/attachment.html>


More information about the swift-dev mailing list