Description
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.