[Issue 5713] Broken final switch on ints
https://issues.dlang.org/show_bug.cgi?id=5713 Dlang Bot changed: What|Removed |Added Status|REOPENED|RESOLVED Resolution|--- |FIXED --- Comment #18 from Dlang Bot --- dlang/dlang.org pull request #2841 "fix Issue 5713 - Broken final switch on ints" was merged into master: - 9455b02ee18d49a05af695ed91cfbed84366de64 by Walter Bright: fix Issue 5713 - Broken final switch on ints https://github.com/dlang/dlang.org/pull/2841 --
[Issue 5713] Broken final switch on ints
https://issues.dlang.org/show_bug.cgi?id=5713 Walter Bright changed: What|Removed |Added Keywords|wrong-code | --- Comment #17 from Walter Bright --- It is not an issue of wrong-code. --
[Issue 5713] Broken final switch on ints
https://issues.dlang.org/show_bug.cgi?id=5713 --- Comment #16 from Walter Bright --- What happens is the compiler inserts a default that throws an exception. This is compatible with what the spec says. I added a clarification to the spec. --
[Issue 5713] Broken final switch on ints
https://issues.dlang.org/show_bug.cgi?id=5713 Dlang Bot changed: What|Removed |Added Keywords||pull --- Comment #15 from Dlang Bot --- @WalterBright created dlang/dlang.org pull request #2841 "fix Issue 5713 - Broken final switch on ints" fixing this issue: - fix Issue 5713 - Broken final switch on ints https://github.com/dlang/dlang.org/pull/2841 --
[Issue 5713] Broken final switch on ints
https://issues.dlang.org/show_bug.cgi?id=5713 Walter Bright changed: What|Removed |Added See Also||https://issues.dlang.org/sh ||ow_bug.cgi?id=5714, ||https://issues.dlang.org/sh ||ow_bug.cgi?id=6060 --
[Issue 5713] Broken final switch on ints
https://issues.dlang.org/show_bug.cgi?id=5713 --- Comment #14 from bearophile_h...@eml.cc --- Another simple case worth supporting: void main() { foreach (immutable i; 0 .. 3) { final switch (i) { case 0: break; case 1: break; case 2: break; } } } --
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 --- Comment #13 from bearophile_h...@eml.cc 2012-12-26 04:13:35 PST --- See also this thread: http://forum.dlang.org/thread/hoczugrnzfbtvpnwj...@forum.dlang.org I think this code should be supported, because here the compiler is able to statically enforce that every possible ushort value is covered by exactly one of the final switch cases: void main () { ushort x; final switch (x) { case 0: .. case 1000: break; case 1001: .. case ushort.max: break; } } See also issue 5714 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 bearophile_h...@eml.cc changed: What|Removed |Added Severity|enhancement |major --- Comment #12 from bearophile_h...@eml.cc 2012-12-23 22:57:35 PST --- This issue was definitively mislabelled, this is clearly a bug, and even significant. Bumped to major. void main() { bool b; final switch (b) { case true: break; } } It compiles without errors. At runtime gives: core.exception.SwitchError@test(3): No appropriate switch clause found -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 Rene changed: What|Removed |Added CC||renedu...@yahoo.com.br --- Comment #11 from Rene 2012-08-31 09:48:27 PDT --- Ok, this change broke my code that I wrote *following the spec*. And it only breaks on runtime! The fix was simple (adding a case 0: break;), but still the spec needs to be updated if you guys are changing it. And breaking changes that don't give compiler errors on now-wrong-code are quite nasty... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 yebblies changed: What|Removed |Added CC||yebbl...@gmail.com --- Comment #10 from yebblies 2012-02-06 02:38:35 EST --- (In reply to comment #9) > Then maybe we need a "wrong_specs" tag in Bugzilla, for the situations where > the compiler is working as the spec say, but where the spec themselves look > wrong. The problem with this is that it is completely subjective. The line between 'I wish D had this' and 'It is a design error that D doesn't have this' varies from person to person, and without hard rules having a keyword to distinguish between them is useless. I don't have a solution for this, but the people fixing bugs and implementing features are well aware that enhancement means 'not a priority' not 'won't happen'. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 --- Comment #9 from bearophile_h...@eml.cc 2012-02-05 06:59:27 PST --- Turning bugs into enhancement requests is a good way to reduce bug count, but it doesn't address the problems. "enhancement" sounds like something that someone wants to add, like switching on structs. But this is not the case. Given a sane definition of final switch, asking the compiler to refuse code like this at compile-time is not an enhancement: void main() { int x = 100; final switch (x % 3) { case 0: break; case 1: break; } } Then maybe we need a "wrong_specs" tag in Bugzilla, for the situations where the compiler is working as the spec say, but where the spec themselves look wrong. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 Denis changed: What|Removed |Added Status|RESOLVED|REOPENED Resolution|FIXED | --- Comment #8 from Denis 2012-01-24 15:09:27 MSK --- As bearophile wrote in issue 6060 description: >in 5713 I don't like an error message (and I'd like the compiler to enforce >the presence of the cases for 0,1, and 2) So this issue requires the following function be compilable _iff_ every `case` is present: --- void f(int x) { final switch (x % 3) { case -2: case -1: case 0: case 1: case 2: } } --- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 Denis changed: What|Removed |Added CC||verylonglogin@gmail.com --- Comment #7 from Denis 2012-01-24 15:01:58 MSK --- (In reply to comment #5) > An example from Timon Gehr, this gives no compilation errors, and prints > nothing: > > > import std.stdio; > enum Mode { nothing, read, write } > void main() { > final switch (Mode.read | Mode.write) { > case Mode.nothing: writeln(0); break; > case Mode.read:writeln(1); break; > case Mode.write: writeln(2); break; > } > } Created issue 7358 inspired by this (inspired but different because this code can be statically rejected). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 Walter Bright changed: What|Removed |Added Status|NEW |RESOLVED CC||bugzi...@digitalmars.com Resolution||FIXED -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 --- Comment #6 from github-bugzi...@puremagic.com 2012-01-24 01:04:53 PST --- Commit pushed to https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/11738ba260ced4d522d2334c5e99059a2517035d fix Issue 5713 - Broken final switch on ints -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 --- Comment #5 from bearophile_h...@eml.cc 2011-09-07 10:15:54 PDT --- An example from Timon Gehr, this gives no compilation errors, and prints nothing: import std.stdio; enum Mode { nothing, read, write } void main() { final switch (Mode.read | Mode.write) { case Mode.nothing: writeln(0); break; case Mode.read:writeln(1); break; case Mode.write: writeln(2); break; } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 --- Comment #4 from bearophile_h...@eml.cc 2011-08-20 14:05:58 PDT --- This code is a reduction of real code, with small changes. It shows why this final switch brokeness makes final switch not as safe as advertised: void main() { enum Foo { A, B } enum Bar { C = 5, D = 6 } int fe; // first mistake, fe is not Foo bool someCondition = true; if (someCondition) fe = Bar.C; // second mistake, fe is not assigned to a Foo final switch (fe) { case Foo.A: break; case Foo.B: break; } } The code contains two mistakes, the first is giving fe int type instead of Foo. The second mistake is assigning to fe an invalid enum value. The final switch doesn't catch the wrong enum value of fe, and it asks for no default case because it's supposed to be complete. The final switch spec need to be improved. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 --- Comment #3 from bearophile_h...@eml.cc 2011-05-26 15:57:36 PDT --- See also bug 6060 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 --- Comment #2 from bearophile_h...@eml.cc 2011-03-07 16:17:51 PST --- See also bug 5714 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 5713] Broken final switch on ints
http://d.puremagic.com/issues/show_bug.cgi?id=5713 Stewart Gordon changed: What|Removed |Added Keywords||spec, wrong-code CC||s...@iname.com --- Comment #1 from Stewart Gordon 2011-03-07 05:39:56 PST --- At first I thought maybe it was ignoring the error out of knowledge that x % 3 == 1 in this instance. But no - it still accepts (and runs without even a SwitchError) if I change x to 101. But you'd need to cover -1 and -2 as well for this to make sense. The spec doesn't actually disallow it: http://www.digitalmars.com/d/2.0/statement.html#FinalSwitchStatement "A final switch statement is just like a switch statement, except that: * No DefaultStatement is allowed. * No CaseRangeStatements are allowed. * If the switch Expression is of enum type, all the enum members must appear in the CaseStatements. * The case expressions cannot evaluate to a run time initialized value." But this seems to be a mistake, and that no SwitchError is thrown strikes me as a bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---