-
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.model-exhaustivenessImplementation of exhaustiveness checkingImplementation of exhaustiveness checking
Description
This came up in a discussion with @brianquinlan.
Sometimes a package author wants to prevent clients from exhaustively switching on an enumerated type, so that in the future they can add enumerated values without breaking clients. One way to do this is to create a dummy private enumerated value (e.g. _unknown); this ensures that it's impossible for a client to exhaustively switch on the enum type; they have to use a default clause or a wildcard pattern.
Unfortunately, this approach isn't very ergonomic, because if the client tries to exhaustively match such an enum type:
- The problem message they get is "The type TYPE isn't exhaustively matched by the switch cases since it doesn't match the pattern 'TYPE._unknown'". This seems to imply that the user ought to be able to fix the problem by adding a switch case for
TYPE._unknown, but they can't. - The correction message they get is "Try adding a wildcard pattern or cases that match 'TYPE._unknown'." Again, adding a case that matches
TYPE._unknownisn't possible. - The analysis server offers a quick fix "Add missing switch cases", which does nothing. Instead, a quick fix should be offered that adds a default clause or a wildcard pattern.
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.model-exhaustivenessImplementation of exhaustiveness checkingImplementation of exhaustiveness checking