Skip to content

Analyzer incorrect non-constant nullaware list/set element #62117

@lrhn

Description

@lrhn

Example:

void main() {
  const b = identical(1, 1.0);
  const Object? v = b ? 0 : null;
  const l1 = [?v]; // OK, a `?v` is a constant expression.
  const l2 = [if (b) ?v]; // Not OK here?
  const l3 = [if (b) v else ?v]; // Not OK here?

  const s1 = {?v}; // Different bug!
  const s2 = {if (b) ?v}; // Not OK here?
  const s3 = {if (b) v else ?v}; // Not OK here?
}

The ?v in l2, l3, s2 and s3 makes the analyzer say

The values in a const list literal must be constants.

It has no issue treating the same ?v element as constant outside of a conditional. The CFE accepts the program.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.dart-model-analyzer-specIssues with the analyzer's implementation of the language specfeature-null-aware-elementsImplementation of the Null-aware elements featuretype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions