<div dir="ltr"><div>Typealiases in extensions currently does not work as expected or intended, as can be demonstrated by the following example:<br></div><div><br></div><div>struct S&lt;A&gt; {</div><div>    var hmm: (A, B, C)</div><div>}</div><div>extension S where A == Bool {</div><div>    typealias B = A</div><div>    static func printB() { print(B.self) }</div><div>}</div><div>extension S where A == Float {</div><div>    typealias C = A</div><div>    static func printC() { print(C.self) }</div><div>}</div><div>let a = S(hmm: (&quot;strange&quot;, true, Float(42.1)))</div><div>dump(a)</div><div><br></div><div>The above program will compile (!) and print:</div><div>▿ VectorAttempt4_Xc9b4.S&lt;Swift.String&gt;</div><div>  ▿ hmm: (3 elements)</div><div>    - .0: &quot;strange&quot;</div><div>    - .1: true</div><div>    - .2: 42.0999985</div><div><br></div><div>(SR-5440)</div><div><br></div><div>Here, the intended behavior would most probably involve a compile time error for the declaration of `hmm: (A, B, C)`.</div><div><br></div><div>But in the following example, it is not that easy to guess the intended behavior, and so I&#39;d like to ask for your thoughts about it:</div><div><br></div><div>protocol P {</div><div>    associatedtype A</div><div>    typealias B = Int</div><div>}</div><div>extension P where A == Bool {</div><div>    typealias B = Float // Compiles, but should it?</div><div>}</div><div>extension P where A == Double {</div><div>    typealias B = String // ERROR: Invalid redeclaration of `B`</div><div>}</div><div><br></div><div>(SR-5392)</div><div><br></div><div>Note that Bool, Int, Float, Double and String can be any types; ie the topmost overloaded-typealias-in-an-extension will always compile but the rest will fail.</div><div><br></div><div>So, should both compile (thus allow overloading of `B`) or should both be considered redeclarations?</div><div><br></div><div>I (naively) think it would be nice if both compiled, ie if it was possible to overload associated types in constrained extensions, since it could open up some interesting possibilities (or perhaps only a can of worms?).</div><div><br></div><div>/Jens</div><div><br></div></div>