Skip to content

Invalid const constructor calls produce multiple diagnostics where one would do #59693

@DanTup

Description

@DanTup

There are several tests in pkg/analyzer/test/src/dart/constant/evaluation_test.dart (once https://dart-review.googlesource.com/c/sdk/+/399661 has landed) that test code with invalid constants. In some cases they produce multiple diagnostics that overlap or are close together that are all related to the same issue. It would be nice if these could be combined (or the redundant ones discarded).

For example:

    await assertErrorsInCode('''
class A {
  const A({required int x });
}
class B extends A {
  const B({required super.x });
}
const a = B();
''', [
      error(CompileTimeErrorCode.MISSING_REQUIRED_ARGUMENT, 106, 1),
      error(CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE, 106,
          3),
      error(CompileTimeErrorCode.INVALID_CONSTANT, 106, 3,
          contextMessages: [message(testFile, 88, 1)]),
    ]);
    await assertErrorsInCode('''
class A {
  const A(int x);
}
class B extends A {
  const B(super.x);
}
const a = B();
''', [
      error(CompileTimeErrorCode.NOT_ENOUGH_POSITIONAL_ARGUMENTS_NAME_SINGULAR,
          84, 1),
      error(CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE, 82,
          3),
      error(CompileTimeErrorCode.INVALID_CONSTANT, 82, 3,
          contextMessages: [message(testFile, 66, 1)]),
    ]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-uxtype-uxA user experience or user interface related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions