Skip to content

Sealed classes & interfaces #4768

@oprypkhantc

Description

@oprypkhantc

Feature request

Introduce support for sealed classes & interfaces. A sealed class-like is such that it's children (extends and implementations) can only be defined under the same namespace it is. A sealed class must be declared abstract because such classes are guaranteed to be extended and, therefore, shouldn't be an implementation themselves.

Reference: https://kotlinlang.org/docs/sealed-classes.html

This is very similar to a draft "Tagged Enums" PHP RFC, except with support for interfaces and spanning implementations accross the whole namespace, instead of just one file: https://wiki.php.net/rfc/tagged_unions

The feature should be pretty easy to implement: one annotation, one reflection method isSealed() and a rule that makes sure extended class/implemented interface is either not sealed or is under the same namespace as the @sealed marked class/interface.

Further improvements, such as exhaustive switch/match checks, could be implemented down the line.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions