Skip to content

[Class Modifiers] Consider allowing type aliases to remove capabilities. #2920

Open
@leafpetersen

Description

@leafpetersen

[This is not a proposal for the current release, but leaving this as a quick note for something we could consider in future releases]

Some of the design of the class modifiers feature is driven by use cases in which a user may wish to have more capabilities within a library than they wish to expose externally. We support this to a certain extent since users are free to ignore restrictions within their own libraries, but as @lrhn notes here there are still places where finer granularity might be useful. One approach to handling this might be to allow class modifiers to be placed on appropriate type aliases to expose an existing class with fewer capabilities. That is, given:

class A {}

we would allow

base typedef ABase = A;

Here, A would support both implementation and extension, but ABase would be restricted to extension. This would support use cases such as those described in #2908:

class _SetBase<T> {...}
class SuperSet<T> extends _SetBase<T> {...}
base typedef SetBase<T> = _SetBase<T>;

Here, we allow SuperSet<T> to be extended or implemented arbitarily (since _SetBase is not restricted), but the exposed name SetBase will only support extension.

cc @dart-lang/language-team

Metadata

Metadata

Assignees

No one assigned

    Labels

    class-modifiers-laterIssues related to "base", "final", "interface", and "sealed" on classes and mixins, tbd later

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions