Skip to content

Control-flow collecion issue for the set literals #60087

@sgrekhov

Description

@sgrekhov

The code below produces an error in both CFE and the analyzer.

main() {
  int i = 0;

  <int>{
    if (2 > 1) i // Ok
  };

  {
    if (2 > 1) i // Error: Expected ';' after this.
  };

  {
    if (2 > 1) i, // Error: Expected ';' after this.
  };

  <int>{
    if (2 > 1) i; // Error: Expected '}' before this.
  };

  {
    if (2 > 1) i; // Ok
  };
// But!
  print({
    if (2 > 1) i // Ok
  });

  print({
    if (2 > 1) i; // Error: Expected '}' before this.
  });
}

According to the grammar ; is not allowed in set literals. So, I believe, that the extected result is:

  {
    if (2 > 1) i // Should be allowed with and without trailing `,`
  };
  {
    if (2 > 1) i; // Expect an error
  };

cc @eernstg to confirm.

Dart SDK version: 3.8.0-66.0.dev (dev) (Sun Feb 2 20:05:47 2025 -0800) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-as-intendedClosed as the reported issue is expected behaviortype-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions