sqf icon indicating copy to clipboard operation
sqf copied to clipboard

Warn for duplicate case entry in switch

Open tyra314 opened this issue 6 years ago • 0 comments

When a switch contains a case entry with the same value twice, only one the first on will be executed. So a warning in a static case would be nice.

foo = 0;
switch (foo) do {
    case (0): {
        hint "You'll see this.";
    };
    case (0): {
        hint "You won't see this."
    };
};

And yes, I did basically that FeelsBadMan

*edit: Of course it won't only happen for literals

bar = 0;
foo = 0;
switch (foo) do {
    case (bar): {
        hint "You'll see this.";
    };
    case (bar): {
        hint "You won't see this."
    };
};

And the holy grail would be doing some static analysis to catch this:

bar = 0;
foo = 0;
switch (foo) do {
    case (0): {
        hint "You'll see this.";
    };
    case (bar): {
        hint "You won't see this."
    };
};

tyra314 avatar Oct 19 '18 17:10 tyra314