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

Formatter doesn't honor "else if" #333

Closed
DartBot opened this issue Jun 5, 2015 · 3 comments
Closed

Formatter doesn't honor "else if" #333

DartBot opened this issue Jun 5, 2015 · 3 comments
Assignees
Labels

Comments

@DartBot
Copy link

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/778217?v=3" align="left" width="96" height="96"hspace="10"> Issue by tatumizer
Originally opened as dart-lang/sdk#17363


BEFORE:
main() {
  var zero = 0;
  if (0 == 0) {
    zero=0;
  } else if (0 == 1) {
    zero=1;
  } else if (0 == 2) {
    zero =2;
  }
  print(0);
}
AFTER:
main() {
  var zero = 0;
  if (0 == 0) {
    zero = 0;
  } else {
    if (0 == 1) {
      zero = 1;
    } else {
      if (0 == 2) {
        zero = 2;
      }
    }
  }
  print(0);
}

A lot of unnecessary "{}" inserted. Apparently, formatter doesn't think of "else if" as a valid construct, but it is.
Note it's not the same problem as orphans as per issue #316.
In the latest dev release, orphans produce the same output as above, that is
foo() {
  var zero = 0;
  if (0 == 0)
    zero=0;
  else if (0 == 1)
    zero=1;
  else if (0 == 2)
    zero =2;
 
  print(0);
}
is now formatted exactly as in AFTER section above, inserting unnecessary {}. Whereas it was supposed to insert minimal amount of {}, so that the thing after formatting should look as in BEFORE example above.

Another small issue: I had to insert print(0) in the end; without it, formatter prints red error message at the bottom: expected EOF but got '}'

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/778217?v=3" align="left" width="48" height="48"hspace="10"> Comment by tatumizer


Please change the title, it sounds rude with respect to formatter. Something like: formatter doesn't honor "else if". My apologies.
/Alex

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/67586?v=3" align="left" width="48" height="48"hspace="10"> Comment by pq


Thanks for the report. I updated the title as you suggested but I think the first one wasn't too far off. Looks like mangling to me!

I've upped the priority too since this breaks the basic contract (e.g., formats should be semantic preserving).


Set owner to @pq.
Added this to the 1.3 milestone.
Removed Priority-Unassigned label.
Added Priority-High, Area-Formatter, Triaged labels.
Changed the title to: "Formatter doesn't honor "else if"".

@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

<img src="https://avatars.githubusercontent.com/u/67586?v=3" align="left" width="48" height="48"hspace="10"> Comment by pq


Fixed w/ dart-lang/sdk@8a54c6f.


Added Fixed label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants