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

Defining a variable with the name 'name' in an enum causes a syntax error in Flutter Web #49021

Closed
RahmiTufanoglu opened this issue May 15, 2022 · 4 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-dev-compiler

Comments

@RahmiTufanoglu
Copy link

RahmiTufanoglu commented May 15, 2022

Describe the issue
After updating to Dart 2.17 and Flutter 3.0 I made use of the new capabilities of Enums. However, the explicit creation of a variable with the name 'name' causes an 'Identifier 'name' has already been declared' in the Chrome console after running the Flutter Web application.

To Reproduce

enum MyEnum {
  hello(name: 'Foo'),
  world(name: 'Bar');

  final String name;

  const MyEnum({required this.name});
}

Expected behavior
Flutter Web application will not be executed. Google Chrome console shows 'Uncaught SyntaxError: Identifier 'name' has already been declared.

Additional context
Flutter for mobile still works fine. The issue is only related to Flutter Web.

@RahmiTufanoglu RahmiTufanoglu changed the title Defining a variable with the name 'name' in an enum causes an syntax error in Flutter web Defining a variable with the name 'name' in an enum causes a syntax error in Flutter web May 15, 2022
@RahmiTufanoglu RahmiTufanoglu changed the title Defining a variable with the name 'name' in an enum causes a syntax error in Flutter web Defining a variable with the name 'name' in an enum causes a syntax error in Flutter Web May 15, 2022
@srawlins srawlins transferred this issue from dart-lang/linter May 15, 2022
@srawlins srawlins added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label May 15, 2022
@srawlins
Copy link
Member

Perhaps a dart2js or DDC issue?

@liamappelbe
Copy link
Contributor

Fixed in https://dart-review.googlesource.com/c/sdk/+/245082

Interestingly this was a bug in the CFE, but since enum constructors are never invoked by the user, the VM wasn't compiling them. That's why it only showed up on the web.

@liamappelbe
Copy link
Contributor

liamappelbe commented May 20, 2022

Actually, DDC might need to separately fix this issue. I don't know enough about DDC to know for sure (not sure if they use the same front end), so I'll leave this issue open for now.

@liamappelbe
Copy link
Contributor

Apparently DDC uses the same CFE as the VM and dart2js, so my CFE fix should have fixed the bug for DDC too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-dev-compiler
Projects
None yet
Development

No branches or pull requests

4 participants