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

Analyzer doesn't allow ! selector in constants #59800

Open
sgrekhov opened this issue Dec 24, 2024 · 1 comment
Open

Analyzer doesn't allow ! selector in constants #59800

sgrekhov opened this issue Dec 24, 2024 · 1 comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

The below works well in VM but produces an error in the analyzer.

const answer = "42"!; // Analyzer error. Const variables must be initialized with a constant value.

main() {
  print(answer);
}

Constant expression allows ! selector, therefore, I believe, it's an analyzer issue.

@lrhn @eernstg please confirm.

Dart SDK version: 3.7.0-274.0.dev (dev) (Thu Dec 19 20:06:50 2024 -0800) on "windows_x64"

@sgrekhov sgrekhov added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Dec 24, 2024
@lrhn
Copy link
Member

lrhn commented Dec 25, 2024

I'd be fine with ! being a constant expression. However, I didn't find it in the "Constant Objects" section of the NNBD specification. Was it added later @eernstg?

(I did find a section saying that the section on as checks being covariant should be changed to'

\item An expression of the form \code{$e$\,\,as\,\,$T$} or \code{$e$\,\,is\,\,$T$} is potentially constant if $e$ is a potentially constant expression and $T$ is a potentially constant type expression, and it is further constant if $e$ is constant.

That should also say "and $T$ is constant" at the end.)

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Dec 27, 2024
@keertip keertip added analyzer-spec Issues with the analyzer's implementation of the language spec P3 A lower priority bug or feature request labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants