Skip to content

[analyzer] No error in case of ?. in a constant expression #60673

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
sgrekhov opened this issue May 5, 2025 · 1 comment
Open

[analyzer] No error in case of ?. in a constant expression #60673

sgrekhov opened this issue May 5, 2025 · 1 comment

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented May 5, 2025

With the recent change the following code produces and error in CFE but no error in the analyzer.

const String? c1 = null;
const int? c2 = c1 == null ? null : c1?.length;  // Error: Null-aware property access can't be used in a constant expression.

main() {
  print(c2);
}

@eernstg please confirm that there should be an analyzer error as well.

Dart SDK version: 3.9.0-edge.cddee72854b2c735148751f08eb0cc51d05854c9 (main) (Mon May 5 01:50:25 2025 -0700) on "linux_x64"

@eernstg
Copy link
Member

eernstg commented May 5, 2025

Yes, "this is not a constant expression" is an error for any static analysis, analyzer or CFE, when a constant expression is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants