Skip to content

[enhanced-enums] A value declaration is a constant context #48232

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

Open
1 of 2 tasks
eernstg opened this issue Jan 27, 2022 · 3 comments
Open
1 of 2 tasks

[enhanced-enums] A value declaration is a constant context #48232

eernstg opened this issue Jan 27, 2022 · 3 comments
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented Jan 27, 2022

Consider the following program:

enum E {
    v([]); // No error.
  const E(_);
}

The program uses --enable-experiment=enhanced-enums. It does not have any errors, in particular, [] can be used as an actual argument because the spec has:

where args are considered as occurring in a const context, ...

However, the CFE reports an error at [] (two, actually):

n017.dart:2:7: Error: Constant expression expected.
Try inserting 'const'.
    v([]);
      ^
n017.dart:2:7: Error: Non-constant list literal is not a constant expression.
    v([]);
      ^

The analyzer rejects the program as follows:

ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER|/usr/local/google/home/eernst/lang/dart/scratch/202201/n017.dart|3|9|1|A constant constructor can't call a non-constant super constructor of 'Enum'.

which means that the analyzer may or may not have the same fault, but we don't get to see it because we encounter an error with the Enum constructor (which could be a fault in the analyzer, or in the declaration of Enum, or both).

So we have at least one platform where there is a need to make this change: An enum value declaration is a constant context.


Subtasks:

@eernstg eernstg added area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 27, 2022
@eernstg
Copy link
Member Author

eernstg commented Jan 27, 2022

@scheglov, do you agree that the CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER issue that seems to affect the analysis of every enhanced enum declaration could mask errors on the enum members? Is it expected to be resolved soon?

@scheglov
Copy link
Contributor

Yes, I agree. https://dart-review.googlesource.com/c/sdk/+/230321 should fix this.

@eernstg
Copy link
Member Author

eernstg commented Jan 27, 2022

Thanks! I added #48237 just in case there is a need to change the analyzer as well.

copybara-service bot pushed a commit that referenced this issue Jan 27, 2022
…tors.

Bug: #48232
Change-Id: I8621f04c67bf8f3ef3ec82945516613058b12029
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230321
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants