[SR-4468] "Switch must be exhaustive" should suggest at least 1 incompletely handled case. #47045
Labels
compiler
The Swift compiler in itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
improvement
Attachment: Download
Environment
Xcode 8.3, Swift 3.1
Additional Detail from JIRA
md5: 952fe45970b7ad1ce8b237d8be29d7ba
Issue Description:
The error message "Switch must exhaustive, consider adding a default clause" should be improved by stating at least one case that is incompletely handled so the programmer can immediately do something to start fixing the problem.
Consider the following code in Swift 3.1, which will give the error "Switch must exhaustive, consider adding a default clause":
Upon seeing the error message, you can't immediately fix the problem. Instead, you need to slowly and painstakingly analyze the code, comparing cases in the enum to cases in the switch to find which case is accidentally omitted. This can be difficult in the presence of where clauses and can be very time consuming for enums with a large number of cases.
This is work that the compiler should be able to do (theoretically, it has already done the work to recognize the need for the error in the first place).
A more helpful message would be: "Switch must be exhaustive; cases, including 'r', are incompletely handled. Consider adding a default clause."
The text was updated successfully, but these errors were encountered: