File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -2168,11 +2168,17 @@ else
21682168 cs.exp = cs.exp.implicitCastTo(sc, sw.condition.type);
21692169 cs.exp = cs.exp.optimize(WANTvalue | WANTexpand);
21702170
2171+ Expression e = cs.exp;
2172+ // Remove all the casts the user and/or implicitCastTo may introduce
2173+ // otherwise we'd sometimes fail the check below.
2174+ while (e.op == TOKcast)
2175+ e = (cast (CastExp)e).e1;
2176+
21712177 /* This is where variables are allowed as case expressions.
21722178 */
2173- if (cs.exp .op == TOKvar)
2179+ if (e .op == TOKvar)
21742180 {
2175- VarExp ve = cast (VarExp)cs.exp ;
2181+ VarExp ve = cast (VarExp)e ;
21762182 VarDeclaration v = ve.var.isVarDeclaration();
21772183 Type t = cs.exp.type.toBasetype();
21782184 if (v && (t.isintegral() || t.ty == Tclass))
Original file line number Diff line number Diff line change 1+ import std.stdio : readf, writeln;
2+ alias TestType = ubyte ;
3+
4+ void main ()
5+ {
6+ TestType a,b,c;
7+ readf(" %s %s %s " , &a, &b, &c);
8+
9+ switch (c)
10+ {
11+ case a : writeln(" a" ) ;break ;
12+ case (cast (ushort )b): writeln(" b" ) ;break ;
13+ default : assert (false );
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments