Skip to content

[enhanced-enums] A value declaration is in a constant context? #2079

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

Closed
eernstg opened this issue Jan 27, 2022 · 2 comments
Closed

[enhanced-enums] A value declaration is in a constant context? #2079

eernstg opened this issue Jan 27, 2022 · 2 comments
Labels
enhanced-enums question Further information is requested

Comments

@eernstg
Copy link
Member

eernstg commented Jan 27, 2022

With the upcoming enhanced-enums feature, we can have arguments to constructors in enum value declarations. They are desugared into the right hand side of the declaration of a static const variable, so presumably they'd be in a constant context?

enum E {
    v([]); // Means `v(const [])`?
  const E(_);
}

Currently, the analyzer fails to handle the above declaration because it reports that Enum does not have the required constant constructor (and this means that no enhanced enum declarations will work at all), but the CFE takes the position that it is not a constant context, and hence it is an error to have [] because no implicit addition of const occurs.

I do not see any plausible future development where enum values will accept non-constant constructor arguments, so we might as well make the value declaration terms a constant context.

@lrhn, @munificent, @leafpetersen, @natebosch, @jakemac53, @stereotype441, WDYT?

@eernstg eernstg added question Further information is requested enhanced-enums labels Jan 27, 2022
@lrhn
Copy link
Member

lrhn commented Jan 27, 2022

Agree. The proposed desugaring makes it a const constructor invocation. The expressions should definitely be in a const context.

It's currently stated as

where args are considered as occurring in a const context, and it’s a compile-time error if they are then not compile-time constants.

@eernstg
Copy link
Member Author

eernstg commented Jan 27, 2022

Aha, I hadn't found that bit in the spec, this means that the fact that it is not treated as a constant context is an issue on implementations: dart-lang/sdk#48232.

So I'll close this issue.

@eernstg eernstg closed this as completed Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhanced-enums question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants