Skip to content

public_member_api_docs: constructors on sealed classes are not really public #59210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matanlurey opened this issue Jul 4, 2023 · 5 comments · Fixed by dart-archive/linter#4535
Assignees
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@matanlurey
Copy link
Contributor

Similar to #57361 (/cc @yjbanov).

Here is a more recent (2023-era) problem, constructors that are not really public.

Consider:

sealed class Fruit {
  Fruit();
}

final class Apple extends Fruit {}
final class Orange extends Fruit {}
final class Banana extends Fruit {}

The Fruit() constructor appears public (i.e. it does not start with _), but in Dart 3+, it is functionally private (that is, it's only accessible in the same library, similar to methods declared with _).

@lrhn
Copy link
Member

lrhn commented Jul 4, 2023

The class is abstract (so constructor cannot be called or torn off) and cannot be subclassed, so there is indeed no valid way to use the constructor.

The constructor could just as well have been private.
It would make sense for, e.g., dartdoc to omit any reference to the constructor, similar to constructors of abstract interface or final classes.

In which case it also shouldn't count as public API.

@pq pq added linter-false-positive type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P3 A lower priority bug or feature request and removed linter-lint-proposal linter-status-pending labels Jul 5, 2023
@pq pq self-assigned this Jul 5, 2023
@pq
Copy link
Member

pq commented Jul 5, 2023

Following the lead of #59189, I think we want to extend this to similarly skip generative constructors in classes that are

  • abstract and interface
  • abstract and final.

@pq
Copy link
Member

pq commented Jul 5, 2023

It would make sense for, e.g., dartdoc to omit any reference to the constructor, similar to constructors of abstract interface or final classes.

fyi @srawlins

@matanlurey
Copy link
Contributor Author

Thanks @pq!

@pq
Copy link
Member

pq commented Jul 5, 2023

You bet @matanlurey. Thanks for the thoughtful report!

@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants