Skip to content

undefined_identifier and other errors are no longer ignorable, causing issues for generated parts #42977

Closed
@greglittlefield-wf

Description

@greglittlefield-wf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions