File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1898,8 +1898,8 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
18981898 ss.condition = ErrorExp.get ();
18991899 ss.condition = ss.condition.optimize(WANTvalue);
19001900 ss.condition = ss.condition.checkGC(sc);
1901- if (ss.condition.op == EXP .error)
1902- conditionError = true ;
1901+ if (conditionError || ss.condition.op == EXP .error)
1902+ return setError () ;
19031903
19041904 bool needswitcherror = false ;
19051905
@@ -1915,7 +1915,7 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
19151915 ss._body = ss._body.statementSemantic(sc);
19161916 sc.inLoop = inLoopSave;
19171917
1918- if (conditionError || ( ss._body && ss._body.isErrorStatement() ))
1918+ if (ss._body && ss._body.isErrorStatement())
19191919 {
19201920 sc.pop();
19211921 return setError ();
@@ -2357,6 +2357,13 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
23572357 lval = fval + 256 ;
23582358 }
23592359
2360+ // If the first and last values aren't integer types, then the toInteger()
2361+ // call above would have resulted in an error.
2362+ if (! crs.first.type.isIntegral() || ! crs.last.type.isIntegral())
2363+ {
2364+ errors = true ;
2365+ }
2366+
23602367 if (errors)
23612368 return setError ();
23622369
Original file line number Diff line number Diff line change 11/*
22TEST_OUTPUT:
33---
4- fail_compilation/diag10783.d(15): Error: no property `type` for `event` of type `diag10783.Event`
5- fail_compilation/diag10783.d(10): struct `Event` defined here
6- fail_compilation/diag10783.d(15): Error: undefined identifier `En`
4+ fail_compilation/diag10783.d(14): Error: no property `type` for `event` of type `diag10783.Event`
5+ fail_compilation/diag10783.d(9): struct `Event` defined here
76---
87*/
98
Original file line number Diff line number Diff line change 11/*
22TEST_OUTPUT:
33---
4- fail_compilation/diag9358.d(13): Error: `x` must be of integral or string type, it is a `double`
5- fail_compilation/diag9358.d(15): Error: `case` expression must be a compile-time `string` or an integral constant, not `1.1`
6- fail_compilation/diag9358.d(16): Error: `case` expression must be a compile-time `string` or an integral constant, not `2.1`
7- fail_compilation/diag9358.d(26): Error: `case` expression must be a compile-time `string` or an integral constant, not `z`
4+ fail_compilation/diag9358.d(11): Error: `x` must be of integral or string type, it is a `double`
5+ fail_compilation/diag9358.d(24): Error: `case` expression must be a compile-time `string` or an integral constant, not `z`
86---
97*/
108void main ()
Original file line number Diff line number Diff line change 1+ /*
2+ TEST_OUTPUT:
3+ ---
4+ fail_compilation/fail22925.d(15): Error: integer constant expression expected instead of `"s"`
5+ fail_compilation/fail22925.d(15): Error: integer constant expression expected instead of `"z"`
6+ fail_compilation/fail22925.d(23): Error: `s` must be of integral or string type, it is a `real`
7+ fail_compilation/fail22925.d(35): Error: cannot implicitly convert expression `2.8` of type `double` to `int`
8+ fail_compilation/fail22925.d(35): Error: cannot implicitly convert expression `4.2` of type `double` to `int`
9+ ---
10+ */
11+ void test1 (string s)
12+ {
13+ switch (s)
14+ {
15+ case " s" : .. case " z" :
16+ break ;
17+ default :
18+ break ;
19+ }
20+ }
21+ void test2 (real s)
22+ {
23+ switch (s)
24+ {
25+ case 1.0 : .. case 2.7 :
26+ break ;
27+ default :
28+ break ;
29+ }
30+ }
31+ void test3 (int s)
32+ {
33+ switch (s)
34+ {
35+ case 2.8 : .. case 4.2 :
36+ break ;
37+ default :
38+ break ;
39+ }
40+ }
Original file line number Diff line number Diff line change 22https://issues.dlang.org/show_bug.cgi?id=22514
33TEST_OUTPUT:
44---
5- fail_compilation/test_switch_error.d(13): Error: undefined identifier `doesNotExist`
6- fail_compilation/test_switch_error.d(16): Error: undefined identifier `alsoDoesNotExits`
7- fail_compilation/test_switch_error.d(19): Error: duplicate `case 2` in `switch` statement
5+ fail_compilation/test_switch_error.d(11): Error: undefined identifier `doesNotExist`
86---
97++/
108
@@ -104,10 +102,6 @@ void test5(int i)
104102TEST_OUTPUT:
105103---
106104fail_compilation/test_switch_error.d(513): Error: undefined identifier `undefinedFunc`
107- fail_compilation/test_switch_error.d(517): Error: `case` expression must be a compile-time `string` or an integral constant, not `Strukt(1)`
108- fail_compilation/test_switch_error.d(518): Error: `case` variables have to be `const` or `immutable`
109- fail_compilation/test_switch_error.d(518): Error: `case` variables not allowed in `final switch` statements
110- fail_compilation/test_switch_error.d(519): Error: `case` variables not allowed in `final switch` statements
111105fail_compilation/test_switch_error.d(522): Error: undefined identifier `undefinedFunc2`
112106---
113107++/
@@ -144,8 +138,6 @@ void errorsWithErrors(int param, immutable int constant)
144138TEST_OUTPUT:
145139---
146140fail_compilation/test_switch_error.d(622): Error: undefined identifier `undefinedFunc`
147- fail_compilation/test_switch_error.d(624): Error: `case` expression must be a compile-time `string` or an integral constant, not `SubtypeOfInt(2)`
148- fail_compilation/test_switch_error.d(625): Error: `case` expression must be a compile-time `string` or an integral constant, not `SubtypeOfIntMethod()`
149141---
150142++/
151143#line 600
You can’t perform that action at this time.
0 commit comments