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

Analyzer complains about switch statements #21822

Closed
DartBot opened this issue Dec 8, 2014 · 3 comments
Closed

Analyzer complains about switch statements #21822

DartBot opened this issue Dec 8, 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

@DartBot
Copy link

DartBot commented Dec 8, 2014

This issue was originally filed by briangepper...@briangeppert.com


What steps will reproduce the problem?

  1. Write a multi-branch switch statement, like the following:

  void toggle() {
    switch(this.state) {
      case 'play': {
        this.state = this.pauseDisabled ? 'stop' : 'pause';
        break;
      }
      case 'pause': {
        this.state = 'stop';
        break;
      }
      case 'stop': {
        this.state = 'play';
        break;
      }
    }
  }

  1. Analyzer complains about the first two branches not ending in a 'break', 'continue', 'return' or 'throw' statement.

What is the expected output? What do you see instead?

I'd expect the analyzer to detect that each branch ends in a 'break'. It does not.

What version of the product are you using?

Chrome Dev Editor (0.18.3450).

On what operating system?

Windows 8.

What browser (if applicable)?

Chrome 39.

@bwilkerson
Copy link
Member

According to the specification:

It is a static warning if the last statement of the statement sequence sk is not a
break, continue, return or throw statement.

Unforunately, the last statement is a block, not one of the listed statements.

Any chance of changing the specification to include (a) a rethrow statement and/or (b) a block whose last statement is one of the listed kinds of statements?


Set owner to @gbracha.
Added Area-Language, Triaged labels.

@DartBot DartBot added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Dec 8, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Mar 1, 2016
@srawlins
Copy link
Member

@gbracha This is fixed now, right? The spec now states:

If s is a non-empty block statement, let s instead be the last statement of the block statement.

@munificent
Copy link
Member

Yep!

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

6 participants