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

Implementations allow void as type of getters. #17650

Closed
lrhn opened this issue Mar 20, 2014 · 3 comments
Closed

Implementations allow void as type of getters. #17650

lrhn opened this issue Mar 20, 2014 · 3 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Mar 20, 2014

The specification allows "void" as the return type of top-level non-external getters only, not any other getter.
It is a syntax error to have "void" as a return type of non-top-level or non-external getters - the grammar does not allow it.

Implementations (VM, dart2js and analyzer) all allow void as a getter return type. Example code:

void get x => null;
//external void get y;
class C {
  void get x => null;
  static void get y => null;
}

main() {
 C.y;
 new C().x;
 x;
// y;
}

This runs and analyzes without errors in the VM, dart2js and the analyzer. If removing the comments for the external getter, it still runs in the and analyzer, and parses in the VM and dart2js.

Should we change the specification?
Should void be allowed as a type in other places too?
Or is this a widespread implementation bug?
Should void be allowed for top-level non-external getters?

@peter-ahe-google
Copy link
Contributor

I'm strongly for allowing this.

A warning will be issued when the getter is used.


Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Mar 20, 2014

Obviously, the spec is inconsistent on this point, as there is nothing about a non-external top level getter that justifies special handling.

I believe the intent was to disallow void as a return type for getters. However:

At this stage of the game, I've been leaning toward changing the spec rather than the implementation if all implementations agree among themselves, unless it is a serious problem. This will of course become much harder once the spec becomes a standard.

So I will fix the spec to allow returnType on getters and make it a static warning.


Set owner to @gbracha.
Added Accepted label.

@lrhn lrhn added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Mar 20, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@munificent
Copy link
Member

Looks like this is done.

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-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants