-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-uxtype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Description
(Parent issue #44897)
As of a42244f, the analyzer now generates context messages in some circumstances explaining why type promotion failed. dartanalyzer and dart analyze expose these messages to the user only when the --verbose option is provided, and the format is not easy to read, e.g.:
Analyzing /usr/local/google/home/paulberry/tmp/test.dart...
Loaded analysis options from /usr/local/google/home/paulberry/tmp/analysis_options.yaml
error • The property 'isEven' can't be unconditionally accessed because the receiver can be 'null'. • /usr/local/google/home/paulberry/tmp/test.dart:4:3 • unchecked_use_of_nullable_value
Variable 'i' could be null due to a write occurring here. at /usr/local/google/home/paulberry/tmp/test.dart:3:3
Try making the access conditional (using '?.') or adding a null check to the target ('!').
https://dart.dev/tools/diagnostic-messages#unchecked_use_of_nullable_value
1 error found.
By contrast, the CFE output looks like this:
../../tmp/test.dart:4:5: Error: Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
Try accessing using ?. instead.
i.isEven;
^^^^^^
../../tmp/test.dart:3:3: Context: Variable 'i' could be null due to a write occurring here.
Try null checking the variable after the write.
i = j;
^
Yesterday we discussed some ideas for how we might improve the presentation of these context messages in the command line analyzer output, such as:
- Using relative file paths rather than absolute ones
- Color coding the error red and the context message green (as CFE does)
- Printing the line of code where the error/context occurs, followed by a line of
^symbols pointing to a particular location on the line - Always printing these context messages (not just when
--verboseis supplied)
Metadata
Metadata
Assignees
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-uxtype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug