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

ConvertForEachToForLoop fixer produces invalid syntax for expression function body with curly braces #51205

Closed
oprypin opened this issue Feb 1, 2023 · 2 comments
Labels
analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@oprypin
Copy link
Contributor

oprypin commented Feb 1, 2023

Example code (yes, it's very weird, this is a mistakenly written set literal):

  [1, -2].forEach((x) => {
        print('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed $x')
      });

Actual replacement contains a syntax error:

  for (var x in [1, -2]) {
    {
        print('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed $x')  // Error: Expected ';' after this.
      };
  }
@oprypin oprypin added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-quick-fix labels Feb 1, 2023
@asashour
Copy link
Contributor

asashour commented Feb 1, 2023

For info, I guess this is case of unnecessary set literal, which is to be tackled soon, to trigger a warning, as reported in #50900, but the fix could also handle it.

@bwilkerson
Copy link
Member

Rather than trying to handle the case of a literal set or map without type arguments as the return value value of the closure, I'd rather see the fix just not be offered in that case.

If we do try to fix it, I believe the fix requires adding the type arguments, not in removing the braces.

MrCsabaToth added a commit to TrackMyIndoorWorkout/TrackMyIndoorWorkout that referenced this issue Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

3 participants