# Subclass always picks its superclass's associatedtype

**URL:** <https://forums.swift.org/t/subclass-always-picks-its-superclasss-associatedtype/47101>\
**Category:** Using Swift\
**Created:** [April 2, 2021, 1:05am UTC](https://forums.swift.org/t/subclass-always-picks-its-superclasss-associatedtype/47101 "2021-04-02T01:05:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Nevin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nevin/32/617_2.png) [@Nevin](https://forums.swift.org/u/Nevin)\
**Post date:** [April 2, 2021, 1:53am UTC](https://forums.swift.org/t/subclass-always-picks-its-superclasss-associatedtype/47101/2 "2021-04-02T01:53:11Z")

</div>

Minified example:

```swift
protocol P { associatedtype A }

class C: P { typealias A = Int }

class D: C { typealias A = String }

extension P {
  static func printA() { print(A.self) }
}

D.printA() // Int
print(D.A.self) // String

```

This behavior occurs because `D`’s conformance to `P` is inherited from `C`.

The only way in which `D` can customize the conformance, is by overriding methods from `C` that satisfy requirements of `P`. Since a `typealias` cannot be overridden, it follows that `D` cannot provide a different one for its conformance to `P`.

Note that the typealias in `D` _does_ work when using `D` directly. It is just not the one used for purposes of conformance to `P`, since that conformance comes from `C`.

• • •

There are a number of other complications surrounding class and subclass conformances to protocols, especially when generics and/or existentials are involved:

[SR–103](https://bugs.swift.org/browse/SR-103) describes the inability of a subclass to override a protocol requirement for which the superclass uses a default implementation from the protocol.

The thread [Need help understanding protocols and generics](https://forums.swift.org/t/need-help-understanding-protocols-and-generics/37564) covers some strange edge-cases. [This post](https://forums.swift.org/t/need-help-understanding-protocols-and-generics/37564/48) by @xwu lists just about every possible combination you can imagine, and explains the behavior in all but the last one, which was discovered by @Lantua a few posts earlier.

---

_[View the full topic](https://forums.swift.org/t/subclass-always-picks-its-superclasss-associatedtype/47101)._
