Permalink
Browse files

Fix issue 9236 CTFE ice on switch + with(EnumType)

When it's with(Type), dont try to interpret it, it's a no-op.
  • Loading branch information...
1 parent e818024 commit d8361c35dca447d10cd4cfe6465b35ec1255767e @don-clugston-sociomantic don-clugston-sociomantic committed Jan 8, 2013
Showing with 39 additions and 0 deletions.
  1. +5 −0 src/interpret.c
  2. +34 −0 test/compilable/interpret3.d
View
@@ -1319,6 +1319,11 @@ Expression *WithStatement::interpret(InterState *istate)
#if LOG
printf("%s WithStatement::interpret()\n", loc.toChars());
#endif
+
+ // If it is with(Enum) {...}, just execute the body.
+ if (exp->op == TOKimport || exp->op == TOKtype)
+ return body ? body->interpret(istate) : EXP_VOID_INTERPRET;
+
START()
Expression *e = exp->interpret(istate);
if (exceptionOrCantInterpret(e))
@@ -4152,6 +4152,40 @@ int testwith()
static assert(testwith());
/**************************************************
+ 9236 ICE switch with(EnumType)
+**************************************************/
+
+enum Command9236 {
+ Char,
+ Any,
+};
+
+bool bug9236(Command9236 cmd)
+{
+ int n = 0;
+ with(Command9236) switch(cmd)
+ {
+ case Any:
+ n = 1;
+ break;
+ default:
+ n = 2;
+ }
+ assert(n == 1);
+
+ switch(cmd) with(Command9236)
+ {
+ case Any:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static assert(bug9236(Command9236.Any));
+
+
+/**************************************************
6416 static struct declaration
**************************************************/

0 comments on commit d8361c3

Please sign in to comment.