Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bwilkerson opened this issue Apr 24, 2025 · 0 comments
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. model-messages Poor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.

Comments

@bwilkerson
Copy link
Member

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.

@bwilkerson bwilkerson added the area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. label Apr 24, 2025
@johnniwinther johnniwinther added the model-messages Poor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE. label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. model-messages Poor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.
Projects
None yet
Development

No branches or pull requests

2 participants