Test case: void f() { int g() { immutable z = 2^^2; // or const, doesn't matter return z; } } Error: Internal error: ../ztc/symbol.c 1041 The error message disappears if you - make g() return something other than z - make z mutable - assign z something other than a power expression
Turns out this has nothing to do with the function being nested. This fails too, with the same error: int g() { immutable z = 2^^2; return z; }
Reduced test case. Doesn't even need a return. It only happens for x^^2 and x^^3, and that's because those cases become comma expressions. Probably something is wrong in fromConstInitializer(). void bug4465() { const a = 2 ^^ 2; int b = a; }
One option would be to change PowExp to stop using CommaExp, but I think that lowering involving comma expressions is such a useful internal feature that it's worth supporting. --------------- PATCH: optimize.c, fromConstInitializer(), line 142. e = expandVar(result, v); if (e) { + // If it is a comma expression involving a declaration, we mustn't + // perform a copy -- we'd get two declarations of the same variable. + // See bugzilla 4465. + if (e->op == TOKcomma && ((CommaExp *)e)->e1->op == TOKdeclaration) + e= e1; + else if (e->type != e1->type && e1->type && e1->type->ty != Tident) { // Type 'paint' operation e = e->copy();
http://www.dsource.org/projects/dmd/changeset/685