cda2815bb1
This warning is similar to the existing `UNREACHABLE_SWITCH_CASE` warning, except that it warns if the `default` clause of a switch statement is unreachable due to all the `case` clasuses fully exhausting the switched type. To make the implementation easier, I changed the API for the `reportExhaustiveness` method in `_fe_analyzer_shared` (which is the primary entry point to the shared exhaustiveness checker). Previously, this method returned a list of `ExhaustivenessError`, where each list element was either an `UnreachableCaseError` (indicating that a certain case was unreachable) or a `NonExhaustiveError` (indicating that the entire switch statement was not exhaustive). If the caller passed in `false` for `computeUnreachable`, `UnreachableCaseError`s would not be returned, so the returned list would either be empty or contain a single `NonExhaustiveError`. The new API renames the types for clarity: - `NonExhaustiveError` becomes `NonExhaustiveness`, to highlight the fact that it's not necessarily an error for the switch's cases to be non-exhaustive; it's only an error if the scrutinee's static type is an "always exhaustive" type and there is no `default` clause. - `UnreachableCaseError` becomes `CaseUnreachability`, to highlight the fact that it's not an error for a case to be unreachable; it's a warning. Also, the new API adds instances of `CaseUnreachability` to an optional user-provided list instead of returning a newly created list; this allows callers to communicate that they don't need to see `CaseUnreachability` information by passing `null`. This frees up the return type to simply be an instance of `NonExhaustiveness` (if the cases are not exhaustive) or `null` (if they are exhaustive). This makes it easier for the analyzer to decide whether to issue the new warning, because it doesn't have to dig around the list looking for an instance of `NonExhaustiveness`. The new warning has an associated quick fix (remove the unreachable `default` clause). This quick fix uses the same `RemoveDeadCode` logic in the analysis server that the existing `UNREACHABLE_SWITCH_CASE` warning uses. Fixes https://github.com/dart-lang/sdk/issues/54575. Bug: https://github.com/dart-lang/sdk/issues/54575 Change-Id: I18b6b7c5249d77d28ead7488b4aae4ea65c4b664 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/378960 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
analysis_server
A long-running process that provides analysis results to other tools.
The analysis server is designed to provide on-going analysis of one or more code bases as those code bases are changing.
Using the server
The analysis server is not intended to be used stand-alone, and therefore does not have a human-friendly user interface.
Clients (typically tools, such as an editor) are expected to run the analysis
server in a separate process and communicate with it using a JSON protocol. The
original protocol is specified in the file analysis_server/doc/api.html
and Language Server Protocol support is documented in
tool/lsp_spec/README.md.
Features and bugs
Please file feature requests and bugs at the issue tracker.