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

Extension types should be able to omit their bodys. #3355

Open
Cat-sushi opened this issue Sep 17, 2023 · 3 comments
Open

Extension types should be able to omit their bodys. #3355

Cat-sushi opened this issue Sep 17, 2023 · 3 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@Cat-sushi
Copy link

Currently, extension types can't omit their body.
An extension type declaration must have a body, even if it is empty.

As a smart alternative of typedef, onliner terminated by semicolon seems important.

@Cat-sushi Cat-sushi added the feature Proposed language feature that solves one or more problems label Sep 17, 2023
@Cat-sushi
Copy link
Author

Ex.

extension type NaturalNumber(int value);

@lrhn
Copy link
Member

lrhn commented Sep 17, 2023

Not planned for the first version.

It's something that can be allowed for classes too, and it's a likely change if we get primary constructors for classes.

I can see a use-case for an extension type which has, or adds, no members, as an opaque wrapper that only exists to distinguish a particular role for the representation object.

(It'll only save one character, so it's not going to be a high priority. I'd rather not introduce it for extension types only, because then it feels weird that you can't do the same thing for classes. Mixins without members is technically possible, but it's only a marker, so you could use an interface class instead, enums without a body won't work, extension without a body has no use. So maybe it really is just class.)

@dart-lang dart-lang deleted a comment Sep 20, 2023
@Cat-sushi
Copy link
Author

FYI
Primary constructors will be able to omit their empty bodys.

Note that an empty class body, `{}`, can be replaced by `;`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants