Skip to content

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

Open
@sgrekhov

Description

@sgrekhov

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestanalyzer-constantsarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.dart-model-analyzer-specIssues with the analyzer's implementation of the language spec

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions