Skip to content
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

could you support @noExtends and @noImplements for abstract class #46331

Closed
Silentdoer opened this issue Jun 11, 2021 · 7 comments
Closed

could you support @noExtends and @noImplements for abstract class #46331

Silentdoer opened this issue Jun 11, 2021 · 7 comments
Labels
analyzer-pkg-meta Issues related to package:meta area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@Silentdoer
Copy link

Silentdoer commented Jun 11, 2021

such as
class Base is an abstract class, I just want people to extends not implements, so I can use @noImplements(annotation in meta.dart):

@noImplements
abstract class Base {
...
}

if people use with class Child implements Base {...} will get a warning by analyzer

@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug labels Jun 11, 2021
@lrhn
Copy link
Member

lrhn commented Jun 11, 2021

This sounds like a request for "interface-less classes". We have other such requests in the language repository, and it might be part of any attempt to make sealed classes (it being a kind of "partially sealed").

It's definitely possible to add this to the analyzer as an annotation only.
There should be no need for @implements since you can prevent extends by not having any public generative constructor.

(I'd probably make it @extendOnly or @noImplements, to signal that it's a restriction. Also avoids any reserved word conflict. A class with @extends @implements looks like it should be able to do both, but if it really prohibits both, then it's confusing.)

@Silentdoer
Copy link
Author

This sounds like a request for "interface-less classes". We have other such requests in the language repository, and it might be part of any attempt to make sealed classes (it being a kind of "partially sealed").

It's definitely possible to add this to the analyzer as an annotation only.
There should be no need for @implements since you can prevent extends by not having any public generative constructor.

(I'd probably make it @extendOnly or @noImplements, to signal that it's a restriction. Also avoids any reserved word conflict. A class with @extends @implements looks like it should be able to do both, but if it really prohibits both, then it's confusing.)

yes, it's my bad, @extends and @implements should be rename to @noImplements and @noExtends like you said.

@Silentdoer Silentdoer changed the title could you support @extends and @implements for abstract class could you support @noExtends and @noImplements for abstract class Jun 11, 2021
@srawlins srawlins added area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-meta P3 A lower priority bug or feature request labels Jun 29, 2021
@bparrishMines
Copy link

This would also be beneficial to federated plugins. Each platform implements a shared platform interface and we are programmatically checking that any class is extended and not implemented. But, there are still situations where a platform implementation can accidentally get around this. An analyzer warning would be easier to work with.

cc @stuartmorgan @pq

@pq
Copy link
Member

pq commented Apr 5, 2022

@pq
Copy link
Member

pq commented Apr 5, 2022

See also @lrhn's proposal: dart-lang/language#704

@jellynoone
Copy link

Also an added benefit with being able to force a client extending your class rather than implementing it is that you are also able to maintain some internal assertions.

For instance, defining a PositiveDuration class which essentially extends Duration and adds an assertion in the constructor so that the duration is indeed positive. (Of course even extending it you could break that assumption but in that case it would really be intentional.)

@bwilkerson bwilkerson added analyzer-pkg-meta Issues related to package:meta and removed area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-meta labels Jul 18, 2022
@srawlins
Copy link
Member

These have all been implemented in the language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-pkg-meta Issues related to package:meta area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

7 participants