Skip to content

Allow sealed base class, because it is useful #3121

@jakemac53

Description

@jakemac53

In general I think our logic for what the valid combinations are was a bit flawed because we used the table for what is allowed in other libraries, but should have used a table based on what is allowed in any library (including the current one). There may be other valid use cases that are not allowed, other than this one, from within the same library.

Use case

You have a sealed class, and you want to ensure all possible implementations of that class are transitive extensions of it.

You can achieve this today by making all the subtypes in your library be themselves base classes, but it could be easy to miss one on accident, in particular when adding new ones. Allowing sealed base would allow you to enforce this property, since base is transitive even within the same library.

Concretely, this is coming up for the Code class in macros, I want every piece of Code to ultimately extend the base sealed class, but they must go through some more specific subtype to get there (DeclarationCode, ExpressionCode, etc).

It is OK for people to build their own subtypes of those, but only through extension. We want to be able to put in some form of validation in their constructors, and ensure that those constraints are met.

Metadata

Metadata

Assignees

No one assigned

    Labels

    class-modifiers-laterIssues related to "base", "final", "interface", and "sealed" on classes and mixins, tbd laterrequestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions