-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Based on a conversation today with @bwilkerson and @jwren, as well as previous conversations with @MichaelRFairhurst and others:
Consider NNBD-enabled code that looks like this:
f(int? x) {
...some code involving the expression x! ... // (1)
...some other code...
if (x == null) { // (2)
...
}
}Flow analysis will determine that since x is null-checked at (1), its type is thereafter promoted from int? to int. Therefore, the test x == null at (2) is guaranteed to evaluate to false, so the analyzer will issue a warning there.
It would be really nice if the user could click on the warning at (2), ask "why was this type promoted?", and be navigated to the null check at (1).
Similar situations exist for other scenarios where types are promoted, such as:
- explicit "is" check.
- assignment of a non-nullable value.
We almost certainly want to expose this information to editors via the analysis server. We might even want to expose it to users of the analyzer CLI.
Note that in order to produce this information we'll need to add the ability for flow analysis to track the "cause" of promotions.