Why can you constrain to final classes and actors?

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

final class Class { }
actor Actor { }
func ƒ(_: some Class, _: some Actor) { }
4 Likes

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.

2 Likes

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

final actor Actor { }

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

2 Likes

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.

8 Likes

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

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

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

1 Like