Description
As of Dart 2.9.0, the undefined_identifier
error is no longer ignorable, along with mixin_of_non_class
, undefined_class
, undefined_identifier
, and invalid_assignment
.
This is problematic for the over_react use-case, in which we generate part files via a build-to-cache builder (meaning the files aren't checked in), and reference some generated members in those files from the original file.
For example:
// source file: foo.dart
import 'package:over_react/over_react.dart';
part 'foo.over_react.g.dart';
UiFactory<FooProps> Foo = _$Foo; // ignore: undefined_identifier
...
// generated file: foo.g.dart
part of 'foo.dart';
UiFactory<FooProps> _$Foo = ...;
...
We use // ignore: undefined_identifier
(as well as project-wide ignores of uri_has_not_been_generated
) so that the source files can analyze cleanly when the generated file doesn't exist or when the generated file is out of date.
In Dart 2.9.0, these ignore comments no longer work, so over_react projects cannot analyze cleanly without first running a build, which is a pretty big hit to the dev experience in IDEs.
We also have some other deprecated boilerplate code that references generated members in other ways:
class FooProps extends _$FooProps
with
// ignore: mixin_of_non_class, undefined_class
_$FooPropsAccessorsMixin {
// ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value
static const PropsMeta meta = _$metaForFooProps;
}
We're in the process of migrating off of this pattern and moving toward that single undefined_identifier
ignore, but we still have a bit of it in our code bases.
This is also closely related to #42832; if the analyzer knew these APIs were generated and could suppress errors without needing ignore comments, that might help solve this problem. However, we'd still have the issue of warnings in outdated generated files.