| Summary: | Enum switch should warn about missing default | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Stephan Herrmann <stephan.herrmann> |
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> |
| Status: | VERIFIED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | amj87.iitr, deepakazad, markus.kell.r, Olivier_Thomann, srikanth_sankaran |
| Version: | 3.4.1 | ||
| Target Milestone: | 3.8 M6 | ||
| Hardware: | Other | ||
| OS: | All | ||
| Whiteboard: | |||
| Bug Depends on: | |||
| Bug Blocks: | 372818, 372840 | ||
|
Description
Stephan Herrmann
Olivier, this should be a trivial fix. Do you think it makes sense for 3.7? Questions are only regarding configurability & suppress warning token. Unfortunately this will require new options and this would add new API field on IProblem. So I would defer to 3.8. Let's no miss API freeze this time. As mentioned, fix should be trivial. We do need a new IProblem but this would fit into existing options: - Irritant: IncompleteEnumSwitch - token: "incomplete-switch" - option: "org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch" Question: is the default "ignore" for IncompleteEnumSwitch really justified? E.g., in bug 207915 the new warning would help explaining another not-configurable error. If the warning is ignored the error (re blank final field) remains unexplained, hm? Srikanth, the fix would be easy, but I don't think another off-by-default warning would help a lot, as I argued in comment 3. What do you think of changing the default for IncompleteEnumSwitch to warning? After all this warning *is* encouraged by the JLS. (In reply to comment #4) > Srikanth, the fix would be easy, but I don't think another off-by-default > warning would help a lot, as I argued in comment 3. > > What do you think of changing the default for IncompleteEnumSwitch to warning? > After all this warning *is* encouraged by the JLS. Sounds like a good idea to me. Resolved for 3.8 M6 via commit d5a32e245b27c645dcf70347396d7253765682d3 I'm leaving the bug open for the corresponding doc-update. (In reply to comment #6) > I'm leaving the bug open for the corresponding doc-update. Looking at the doc I find that CompilerOptions.IncompleteEnumSwitch is rendered as "Enum type constant not covered on 'switch'" Therefore I propose to rephrase the UI label to s.t. like "Incomplete enum switch" :) Alternatively, we could of course create yet another irritant/option, but that sounds like overkill to me. For easy reference: I made the new warning say: The switch on the enum type {0} should have a default case > I'm leaving the bug open for the corresponding doc-update.
That includes Javadoc of JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, right?
It needs updates in the description and for the default value.
FYI: I also opened bug 372840 to provide a quick fix for the new problem. (In reply to comment #8) > > I'm leaving the bug open for the corresponding doc-update. > > That includes Javadoc of JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, right? > It needs updates in the description and for the default value. Sure. To make the dependency between both situations clear I'd make it: When enabled, the compiler will issue an error or a warning whenever an enum switch statement lacks a default case; if no default case is given, additionally one error or warning is issued regarding each enum constant for which a corresponding case label is lacking. OK? > When enabled, the compiler will issue an error or a warning whenever
> an enum switch statement lacks a default case;
> if no default case is given, additionally one error or warning is issued
> regarding each enum constant for which a corresponding case label is lacking.
Sounds good.
Javadoc update is in commit 4de8875392f1614ce3d9b4e720843df3cd1fa2b7 Help update in commit 8718c719fb8c1327d8aae9ff6af012dbe41775c6 (using the wording from bug 372818 comment 2) Verified for 3.8 M6 using Build id: I20120306-0800 (In reply to comment #7) > [..] > Looking at the doc I find that CompilerOptions.IncompleteEnumSwitch is rendered > as "Enum type constant not covered on 'switch'" > > Therefore I propose to rephrase the UI label to s.t. like > "Incomplete enum switch" > :) Is this covered by some bug request? Or was this proposal intentionally dropped? (In reply to comment #14) > (In reply to comment #7) > > [..] > > Looking at the doc I find that CompilerOptions.IncompleteEnumSwitch is rendered > > as "Enum type constant not covered on 'switch'" > > > > Therefore I propose to rephrase the UI label to s.t. like > > "Incomplete enum switch" > > :) > > Is this covered by some bug request? Or was this proposal intentionally > dropped? The UI label has already been updated. |