Skip to content

Invalid constant causes analysis server to stop updating problems view #55535

Open
@stereotype441

Description

@stereotype441

Ran into this problem while coding the other day, and after some experimentation I was able to come up with a narrow repro.

Using VSCode, if I open an empty file and paste in these contents:

class Foo extends Bar {
  static const instance = Foo._();

  const Foo._() : super();
}

class Bar extends Baz {
  const Bar({required super.i});
}

class Baz {
  final int i;

  const Baz({required this.i});
}

No errors show in the problems view.

But if I analyze the same file using dart analyze on the command line, I see:

Analyzing foo.dart...                  0.8s

  error • foo.dart:2:27 • Const variables must be initialized with a constant value. Try changing the initializer to be a constant expression. • const_initialized_with_non_constant_value
  error • foo.dart:2:27 • Invalid constant value. • invalid_constant
           - The error is in the super constructor invocation of 'Bar', and occurs here at foo.dart:1:0.
           - The evaluated constructor 'Bar' is called by 'Foo._' and 'Foo._' is defined here at foo.dart:4:13.
  error • foo.dart:4:19 • The named parameter 'i' is required, but there's no corresponding argument. Try adding the required argument. • missing_required_argument

3 issues found.

If I add an obviously bogus line to the end of the file (like late static int class await(@String);, to name a random example I tried), there are still no errors in the problems view.

The problem seems to be related to the invalid constant declaration static const instance = Foo._();. If I comment it out, then the other errors in the file appear in the problems view. If I then un-comment it, the other errors in the file don't go away.

Reproduced using the latest SDK as of 54abf5e.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onanalyzer-stabilityarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-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