# Why can't protocol which inherits from PAT but constrains its associated types be used as existential?

**URL:** <https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051>\
**Category:** Discussion\
**Tags:** inheritance, protocols, associatedtype\
**Created:** [August 4, 2020, 4:58pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051 "2020-08-04T16:58:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremyabannister](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jeremyabannister/32/10143_2.png) [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Post date:** [August 4, 2020, 4:58pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/1 "2020-08-04T16:58:31Z")

</div>

I was hoping this code would compile, but it does not:

```swift
protocol A {
    associatedtype T
}

protocol B: A where T == Int {
    
}

var demo: B? = nil

```

I get the usual error: `Protocol 'B' can only be used as a generic constraint because it has Self or associated type requirements`. Is this error logically necessary in the same way as it is for fully fledged PATs? Or is the code above perfectly well-defined, and the compiler is simply lacking the necessary implementation?

---

<div class="post-metadata">

**Author:** ![Jumhyn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jumhyn/32/3891_2.png) [@Jumhyn](https://forums.swift.org/u/Jumhyn)\
**Post date:** [August 4, 2020, 5:03pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/2 "2020-08-04T17:03:43Z")

</div>

There was a related discussion [here](https://forums.swift.org/t/protocol-with-clear-generic-requirements-should-not-be-a-generic/37304) a few weeks back. I believe that this is an implementation limitation—this sort of construct would fall out naturally as a consequence of generalized existentials, there just hasn't been enough development effort focused in that area to allow your example to compile.

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [August 4, 2020, 5:05pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/3 "2020-08-04T17:05:31Z")

</div>

I don't think there are any implementation limitations that would prevent this from being supported now.

---

<div class="post-metadata">

**Author:** ![spadafiva](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/spadafiva/32/6635_2.png) [@spadafiva](https://forums.swift.org/u/spadafiva)\
**Post date:** [August 4, 2020, 5:51pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/4 "2020-08-04T17:51:48Z")

</div>

Do you think this would fall under the category of bug/fix improvement, or would it need an evolution proposal to move forward?

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [August 4, 2020, 6:02pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/5 "2020-08-04T18:02:54Z")

</div>

I think it'd be worth an evolution proposal, just to give us time to discuss possible consequences.

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [August 4, 2020, 6:12pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/6 "2020-08-04T18:12:55Z")

</div>

It looks like @anthonylatsis and @Slava_Pestov had worked on a PR to implement this not long ago:

[https://github.com/apple/swift/pull/21576](https://github.com/apple/swift/pull/21576)

---

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [August 5, 2020, 12:27am UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/7 "2020-08-05T00:27:38Z")

</div>

I also just came up with a [similar thread](https://forums.swift.org/t/is-it-possible-to-expand-which-protocols-can-act-as-types/38878).

---

<div class="post-metadata">

**Author:** ![anthonylatsis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anthonylatsis/32/39232_2.png) [@anthonylatsis](https://forums.swift.org/u/anthonylatsis)\
**Post date:** [August 12, 2020, 3:02pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/8 "2020-08-12T15:02:49Z")

</div>

What a dinosaur! 🙂 I am keen to give it another go anytime soon, though.

---

<div class="post-metadata">

**Author:** ![filip-sakel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/filip-sakel/32/8697_2.png) [@filip-sakel](https://forums.swift.org/u/filip-sakel)\
**Post date:** [August 13, 2020, 10:09pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/9 "2020-08-13T22:09:10Z")

</div>

Is anyone working on a proposal? I am willing to write - or to help write - the proposal. With @anthonylatsis help in the implementation and his experience in this issue, I’m positive we could finally fix this agitating behavior of the generics system.

---

<div class="post-metadata">

**Author:** ![anthonylatsis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anthonylatsis/32/39232_2.png) [@anthonylatsis](https://forums.swift.org/u/anthonylatsis)\
**Post date:** [August 13, 2020, 10:49pm UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/10 "2020-08-13T22:49:28Z")

</div>

Hi Filip, that sounds great! Unless one is already under way, consider opening a PR against [GitHub - apple/swift-evolution: This maintains proposals for changes and user-visible enhancements to the Swift Programming Language.](https://github.com/apple/swift-evolution) once you have a draft ready so we can launch a pitch and all start discussing, reviewing and refining the proposal together.

---

<div class="post-metadata">

**Author:** ![jeremyabannister](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jeremyabannister/32/10143_2.png) [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Post date:** [November 14, 2020, 6:03am UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/11 "2020-11-14T06:03:33Z")

</div>

Hi guys (@filip-sakel, @anthonylatsis), I just wanted to poke you both with regard to this feature because it came up again in my work just now, and I'll breath such a sigh of relief when this feature is eventually deployed. I myself am totally swamped with coding items on my todo list so I understand entirely that you guys may not have the time, but I just want to express the gratitude that I'll have if you do end up implementing it!

---

<div class="post-metadata">

**Author:** ![anthonylatsis](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/anthonylatsis/32/39232_2.png) [@anthonylatsis](https://forums.swift.org/u/anthonylatsis)\
**Post date:** [November 16, 2020, 10:18am UTC](https://forums.swift.org/t/why-cant-protocol-which-inherits-from-pat-but-constrains-its-associated-types-be-used-as-existential/39051/12 "2020-11-16T10:18:13Z")

</div>

Hey Jeremy, the proposal is in progress, we just need some time to wrap things up and launch the review process.

> [@jeremyabannister](#):
>
> I just wanted to poke you both with regard to this feature because it came up again in my work just now

Speaking of which, legitimate examples of real-world applications would be very helpful in improving the motivation!
