-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For 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.Poor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.
Description
Consider the following code:
class A {}
class B implements A {}
class C {
late A a;
void m(bool b) {
a = b ? B() : null; // <--
}
}On the marked line there will be a diagnostic of the following form:
A value of type 'B?' can't be assigned to a variable of type 'A'. (invalid_assignment)
Try changing the type of the variable, or casting the right-hand type to 'A'.
While the problem message is technically correct, it would be helpful to have a slightly different message for this particular case, perhaps something of the form
A value of type 'B?' can't be assigned to a variable of type 'A' because it is a nullable type.
The correction, or the second half of it, is not correct. Casting the right-hand side will silence the diagnostic by turning it into a runtime exception. Better advice would be something along the lines of
Try making the variable nullable or change the right-hand to not produce `null`.
FMorschel
Metadata
Metadata
Assignees
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For 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.Poor/undesirable messaging in errors/warnings emitted by the analyzer and/or CFE.