Skip to content

Prohibit extends on public abstract classes with private abstract members. #2654

Open
@AlexanderFarkas

Description

@AlexanderFarkas

This is valid:

abstract class A {
  void _performImpl();

  void perform() {
    ...
    _performImpl();
    ...
  }
}

While extending this class from other file is always invalid.

Activity

srawlins

srawlins commented on Nov 23, 2022

@srawlins
Member

One note: Extending A from within the library where A is declared can be valid.

lrhn

lrhn commented on Nov 23, 2022

@lrhn
Member

The issues with library private members in public interfaces is known. We have no current plans to change that.

This is a particularly useless case, where it might be reasonable to warn the user that the class can be implemented.
I'd recommend not making the class public, rather than introduce rules preventing you from extending the class.

We hope that adding the ability to prevent implementation or extension of classes explicitly (#2242) will allow you to disallow it in the cases where you want to, without the compiler having to figure out whether a use is safe or not.

AlexanderFarkas

AlexanderFarkas commented on Nov 24, 2022

@AlexanderFarkas
Author

When you introduceclosed modifier for classes, lint rule no_non_closed_public_abstract_classes_with_private_abstract_members will be awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @srawlins@lrhn@AlexanderFarkas

        Issue actions

          Prohibit `extends` on public abstract classes with private abstract members. · Issue #2654 · dart-lang/language