# Why can you constrain to final classes and actors?

**URL:** <https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256>\
**Category:** Using Swift\
**Tags:** inheritance\
**Created:** [May 30, 2023, 11:28am UTC](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256 "2023-05-30T11:28:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon9791410](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@anon9791410](https://forums.swift.org/u/anon9791410)\
**Post date:** [May 30, 2023, 11:28am UTC](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256/1 "2023-05-30T11:28:00Z")

</div>

Is it intended to allow for later making the class non-final, or actors inheritable?

```swift
final class Class { }
actor Actor { }
func ƒ(_: some Class, _: some Actor) { }

```

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [May 30, 2023, 1:39pm UTC](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256/2 "2023-05-30T13:39:12Z")

</div>

Anything not explicitly prohibited is allowed. We could ban superclass requirements with a final class but there seems no harm in allowing them. And aesthetically, it would be odd if we allowed `T == C` but not `T: C` when C is final.

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [May 30, 2023, 3:52pm UTC](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256/3 "2023-05-30T15:52:38Z")

</div>

> [@anon9791410](#):
>
> `actor Actor { }`

for reasons i cannot fathom, we are also allowed to write:

```swift
final actor Actor { }

```

it's never been clear to me what purpose this serves or how it is different from an ordinary actor.

---

<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:** [May 30, 2023, 3:55pm UTC](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256/4 "2023-05-30T15:55:39Z")

</div>

As an API contract, being `final` is an assertion that there will never be subclasses of a type, not just that there don't happen to be any right now. For actors we decided not to implement inheritance, but left the door open to it possibly happening later.

---

<div class="post-metadata">

**Author:** ![anon9791410](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@anon9791410](https://forums.swift.org/u/anon9791410)\
**Post date:** [May 30, 2023, 4:21pm UTC](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256/5 "2023-05-30T16:21:28Z")

</div>

> [@Slava\_Pestov](#):
>
> allowed

> [@Joe\_Groff](#):
>
> possibly

Fair enough. Seems to me like it should come with a warning until then. À la

```swift
// Variable 'variable' was never mutated; consider changing to 'let' constant
var variable = 0

```

---

<div class="post-metadata">

**Author:** ![ksluder](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@ksluder](https://forums.swift.org/u/ksluder)\
**Post date:** [May 30, 2023, 4:22pm UTC](https://forums.swift.org/t/why-can-you-constrain-to-final-classes-and-actors/65256/6 "2023-05-30T16:22:49Z")

</div>

What if you wrote a macro that expanded to `A: B`? Would it cause a warning when `B` happens to be a `final` class?
