Skip to content

Expose "why was this type promoted" information through analyzer and analysis server #38773

@stereotype441

Description

@stereotype441

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.

Metadata

Metadata

Assignees

Labels

NNBDIssues related to NNBD ReleaseP2A bug or feature request we're likely to work ondevexp-uxlegacy-area-analyzerUse area-devexp instead.type-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions