On 14/03/2011 14:38, Peter Lundgren wrote:
== Quote from Nebster (evil.nebs...@gmail.com)'s article
Hey,
I'm having some problems iterating over an enumerated associative array.
It comes up with this error at compile time:
  >  Internal error: e2ir.c 4835
I cut the code down to this:
  >  import std.stdio;
  >
  >  enum int[string] assoc = [";": 0, "=": 1, "+": 2, "-": 2, "*": 3,
"/": 3];
  >
  >  void main()
  >  {
  >          foreach(op; assoc.byKey())
  >                  writefln("op: %s", op);
  >  }
What does this mean/how can I get this to work?
Thanks,
Nebster


That's a rather cryptic error message. Hopefully someone smarter than I can 
trace
down why this doesn't have better error reporting. I suspect the problem has
something to do with CTFE. Because you're using an enum, D assumes you want its
value to be computed at compile time. However, currently, associative arrays can
not be evaluated at compile time. Using a static this to initialize the value at
runtime, as already suggested, should solve your issue.

That's not the cryptic part, its the name of the source file and line number, its tripping up here:

AssocArrayLiteralExp::toElem
//...
Type *t = type->toBasetype()->mutableOf();
assert(t->ty == Taarray);                    //line 4835

Though to me that whole function looks like a pile of random abbreviations.

Reply via email to