<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Swift users,<br class=""><br class="">I¡¯m defining a sub-protocol inheriting from parent protocol with associatedtype, and I want to specialized the associatedtype to certain concrete type.<br class=""><br class="">For example, <br class=""><br class="">```swift<br class="">protocol Foo {<br class=""> associatedtype Bar<br class=""> <br class=""> static var bar: Bar { get }<br class="">}<br class=""> <br class="">protocol A: Foo {<br class=""> // I want `Bar` to be `Int`.<br class=""> static var a: Int { get }<br class=""> static var bar: Int { get }<br class="">}<br class=""><br class="">extension A {<br class=""> typealias Bar = Int<br class="">}<br class="">```<br class=""><br class="">I want any class/struct adopting protocol `A` having associatedtype `Bar` specialized to Int. However, I found that structs adopting `A` are still capable of override it.<br class=""><br class="">```swift<br class="">extension A {<div class=""> static var bar: Int {<br class=""> return a<br class=""> }</div><div class=""><br class=""> static func test() {<br class=""> print(bar)<br class=""> }<br class="">}<br class=""><br class="">struct AStruct: A {<br class=""> static let a: Int = 0<br class=""> static let bar: Bool = false // Bar is now Bool<br class=""> // static let bar: Int now becomes invisible.<br class="">}</div><div class=""><br class=""></div><div class="">AStruct.test() // prints 0<br class=""><div class="">```</div></div><div class=""><br class=""></div><div class="">The code above gave same result on both Swift 2.2(Xcode 7.3.1) and Swift 3.0(Xcode 8 beta 3).</div><div class=""><br class=""></div><div class="">It¡¯s this expected behavior? Or am I'm getting something wrong here? What about specializing parent¡¯s associatedtype to certain generic type with newly introduced associatedtype? For example,</div><div class=""><br class=""></div><div class="">```swift</div><span class="">protocol B: Foo {<br class=""> associatedtype T<br class=""> static var bar: Array<T> { get }<br class="">}<br class=""><br class="">extension B {<br class=""> typealias Bar = Array<T><br class="">}<br class=""></span><div class="">```</div><div class=""><br class=""></div><div class="">Any idea would be appreciated.</div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class="">Fengwei</div></body></html>