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

Allow inline metadata instantiation sans parens #13582

Open
DartBot opened this issue Sep 25, 2013 · 4 comments
Open

Allow inline metadata instantiation sans parens #13582

DartBot opened this issue Sep 25, 2013 · 4 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Sep 25, 2013

This issue was originally filed by @seaneagan


Dart supports inline instantiation of annotations, but parens are required even when there are no arguments:

@foo()
int x;

which is ugly to someone coming from Java where parens are not required, so annotation designers often create top-level constants instead. Examples:

@deprecated
@OverRide
@Proxy

This is something that would probably need to be added to the style guide to keep annotations consistent. Also, since metadata is const, the style guide currently requires these to be:

@deprecated
@OverRide
@Proxy

so they would either need to be renamed, or an exception for metadata would need to be added to the style guide. And should the constants still be created if the annotation class has optional arguments, in which case the user needs to decide which to use:

@foo
@foo()

which can't be avoided if the annotation designer wants to add optional arguments after the fact. And refactoring between the 2 forms is more difficult, since the casing of the first letter needs to change ( e.g. @­foo -> @­Foo(bar) ).

Solution:

Allow @­Foo as shorthand for @­Foo()

Then for example we could do:

@deprecated
class Foo {}

and if we wanted to use a hypothetical optional argument, we just add parens:

@deprecated(use: Bar);
class Foo {}

This would mean that if you want to use a Type literal as an annotation, you would need to first assign it to a top-level constant, but that seems like an edge case.

@sethladd
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Oct 16, 2013

This comment was originally written by @seaneagan


Mailing list discussion:

https://groups.google.com/a/dartlang.org/d/msg/misc/bZ5kVTOnUN8/y9julc1anzEJ

I filed issue #14149 for the annotation name issue raised above.

Also please see issue #13862 which is a clear consequence of this bug.

@jmesserly
Copy link

Marked this as blocking #15159.

@gbracha
Copy link
Contributor

gbracha commented Aug 27, 2014

Keeping the rules uniform is always preferable in my mind. At this point the change introduces incompatibilities or more special cases: if K in metadata dart means K() in real dart, what does K() in metadata dart mean in real dart? K() or K()().

I'll leave it open in case we decide to muck with this in 2.0


Set owner to @gbracha.
Added Accepted label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants