Skip to content

Extraneous diagnostic for an argument of an invalid type in a const constructor invocation #60616

@bwilkerson

Description

@bwilkerson

Given the following:

class C {
  final String string;

  const C({required this.string});
}

void f() {
  const C(string: 0);
}

The analyzer currently produces two diagnostics:

A value of type 'int' can't be assigned to a parameter of type 'String' in a const constructor. (const_constructor_param_type_mismatch)

The argument type 'int' can't be assigned to the parameter type 'String'. (argument_type_not_assignable)

Both are reporting the same problem: that an int can't be assigned to a String.

There should only be one diagnostic because there's only one problem. Given that the problem has nothing to do with it being a const constructor, the const_constructor_param_type_mismatch should be suppressed.

Also, the two diagnostics have different highlight ranges. The argument_type_not_assignable highlights the value 0, while the const_constructor_param_type_mismatch includes the argument name in the range (string: 0). Given that there's nothing wrong with the argument name, const_constructor_param_type_mismatch should be changed to highlight only the value of the argument and not include the name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-messagesPoor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions