Open asashour opened 1 year ago
But if the default:
becomes empty and the enum gets updated - won't it create a potential bug?
The dead code starts from the beginning of default:
, so even if it has no statements, the warning would be shown.
The user has to remove the default: ....
clause, or change the exhaustiveness of the enum
or the switch
cases.
If dead code is not triggered, because of the fear that the user would change the code later, then the other dead code should not trigger because the user can change the condition, and this makes the whole dead code not a correct decision, e.g.
void f() {
var x = false;
if (x) {
print('dead');
}
}
currently triggers dead code
, without a concern that false
can be true
if the user changes it later.
Also, I think the main point of exhaustiveness applies to other areas, e.g. patterns
.
currently triggers dead code, without a concern that false can be true if the user changes it later.
If we refer to real world examples, don't you think that a local variable declaration and a global enum declaration (which can be in another file / module from the place it's used) are completely different things in terms of "I see how this change will affect other parts of my codebase"?
Edit: asking mostly out of curiosity
@stereotype441 @johnniwinther
Do we know yet how exhaustiveness checking and flow analysis will treat the default
clause in a switch statement?
The
default
clause should be marked asdead code
.