Open stereotype441 opened 3 years ago
Here is how this error message shows up in VS Code:
Only the first part of the full message is included for some reason.
Assigning to Konstantin. As discussed in the meeting, it would also be good to have a quick fix (or assist) that introduces a local variable.
Hm... Currently we report "not promoted" as attached DiagnosticMessage
s. This way we can use a smaller number of error codes, and attached reasons why the receiver was not promoted to non-nullable. We could specialize PropertyNotPromoted
to report a more specific ErrorCode
with a better message, although it looks that we would have to move the attached message into the main message (the "because" part). Is this what you have in mind?
PropertyNotPromoted
does not tell us where the promotion was attempted. Or do I miss it? If it is not there, we still can support a quick fix for probably the most often case of if (o.x != null) { o.x.foo }
.
PropertyNotPromoted
does not tell us where the promotion was attempted.
You're right. I'll do some digging to see how difficult it would be to add this functionality.
https://dart-review.googlesource.com/c/sdk/+/227900 will add a fix for a few cases.
@mit-mit points out that the errors that occur when the user attempts to promote a property could be clearer. For example, this code:
Produces the error message:
with the following suggested fix:
and then the following context message (pointing to the declaration
int? x;
):Two things are unfortunate about this: (1) The user has to read through a lot of error message text before they get to the meat of the problem (properties can't be promoted). (2) The suggested fix isn't great.
It would be better to have an error message like this:
and a suggested fix like this:
It probably would still be useful to have a context message pointing to the declaration
int? x;
. Maybe it could say something like:Note that this isn't the only error message that could potentially be improved; it's just an example.