Skip to content

[analyzer] Incorrect recursive instance creation in the constant context leads to analyzer not showing any new errors #55078

Open
@incendial

Description

@incendial

I've tried it on a synthetic example, but it didn't work. I assume it's related to generics.
So here is a copy from the codebase:

void fn() {
  test('empty report', () async {
    await ExportsCheckstyleReporter(output).report(
      [],
      const ExportsReportParams(congratulate: true, isAbsolutePath: true), // <-- try replacing ExportsReportParams with ExportsCheckstyleReporter **by typing**
    );

    verifyNever(() => output.write(captureAny()));
  });
}

class ExportsReportParams {
  final bool congratulate;
  final bool isAbsolutePath;
  final bool addSectionHeader;

  const ExportsReportParams({
    required this.congratulate,
    required this.isAbsolutePath,
    this.addSectionHeader = false,
  });
}

abstract class FileReport {
  /// The path to the target file.
  final String path;

  /// The path to the target file relative to the package root.
  final String relativePath;

  const FileReport({required this.path, required this.relativePath});
}


abstract class Reporter<Report extends FileReport, Params> {
  Future<void> report(Iterable<Report> reports, Params additionalParams);

  const Reporter();
}


abstract class CheckstyleReporter<T extends FileReport, P>
    extends Reporter<T, P> {
  static const id = 'checkstyle';

  @protected
  final IOSink output;

  const CheckstyleReporter(this.output);
}

class ExportsCheckstyleReporter
    extends CheckstyleReporter<Never, ExportsReportParams> {
  const ExportsCheckstyleReporter(super.output);

  @override
  Future<void> report(
    Iterable<Never> reports,
    ExportsReportParams additionalParams,
  ) async {
  }
}

Replacing ExportsReportParams with ExportsCheckstyleReporter leads to the analyzer not showing any new errors.

Screen.Recording.2024-03-01.at.13.50.50.mov

If you try to paste the whole void fn() snipped into a file, you'll also get 0 errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onanalyzer-constantsarea-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