Skip to content

Inconsistent "invalid list element constant" errors in analyzer #55467

Open
@srawlins

Description

@srawlins

See this example:

var b = 7;
var w = const A([b]);            // INVALID_CONSTANT
var x = const A([if (true) b]);  // INVALID_CONSTANT
var y = const A([if (false) b]); // NON_CONSTANT_LIST_ELEMENT
var z = const [b];               // NON_CONSTANT_LIST_ELEMENT

class A {
  const A(List<int> p);
}

This yields different errors for w, x, y, and z:

  • w and x: INVALID_CONSTANT
  • y and z: NON_CONSTANT_LIST_ELEMENT

I think it is particularly surprising that x and y have different errors. I think all of the errors should be NON_CONSTANT_LIST_ELEMENT. This inconsistency could represent just the in-progress improvements to errors-that-occur-in-const-instance-creation.

CC @kallentu

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestanalyzer-constantsarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions