Summary: compile-time assertion error in mtype.c: foreach
                    through associative array w/ templated-class as value
           Product: D
           Version: 2.040
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-03-04 11:10:38 PST ---
I'm working on a file with these classes so far:

abstract class State(T:GameEntity)
   string _name;
   @property {
       const string name() const { return _name; }

   this(string name)   { _name = name; }
   (and some empty virtual function decls that get defined by derived classes)
}  // and then the actual implementation for the various State nodes will be
done through derived classes

// so if I had a class DogRobot that derives from GameEntity, then it would
// internally use a StateMachine!(DogRobot), which itself would be using
// State!(DogRobot) for its states.  Somewhere in DogRobot.d it would also
// define those new State!(DogRobot)-derived classes that would then be
// added to the State Machine via addState()
class StateMachine(T:GameEntity)
   State!(T)[string] _states;   // THIS IS LINE 100 IN THE ERROR MESSAGES
MENTIONED LATER -- assoc array for quickly retrieving states by their names

   // public, actual state objects added to the machine here
   void addState(State!(T) state)
      ... (compiles fine) ...

   void linkStates(string fromName, string toName, string eventName)
      ... (compiles fine) ...

   // so far so good, further down I have a function called printGraph() for
debug output, and this is where I've run into assertion problems with DMD 2.040

   void printStates()
       // each and every one of these below causes a compile-time error,
       // though different ones sometimes:

       // this leads to error: "__overloadset is not a template" on line 100
       foreach (string key, State!(T); _states)
          std.stdio.writefln("  %1", key);

       // the rest of these each, individually, result in an assertion error
       // at compile-time which pops up twice.

       // In the actual code I commented-out the previous problematic lines
       // before trying the next approach/flavor.  DMD 2.040 compiler's error
       // for each of these reads as follows:
       // Assertion failure: 'impl' on line 3886 in file 'mtype.c'
       // abnormal program termination
       // Assertion failure: 'impl' on line 3886 in file 'mtype.c'
       // abnormal program termination

       // Various problematic code for THIS error is as follows:

       // first attempt
       foreach (string k; _states.keys)
          std.stdio.writefln("  %1", k);

       // approach #2
       foreach (State!(T) s; _states.values)
          std.stdio.writefln("  %1",;

       // approach #3, but char[] k for a string-type key is probably
       //    incorrect in a different way I'm guessing... just a desperation
       foreach (char[] k; _states.keys.sort)
          std.stdio.writefln("  %1", k);

       // approach #4
       typedef State!(T) tstate;
       foreach (tstate s; _states.values)
          std.stdio.writefln("  %1",;
   }  // end printStates()
}  // end StateMachine class

// end code snippet

In the meantime I can probably get around this problem by getting rid of
templates entirely and very carefully using delegates to act as "plugged-in
behavior"... I was following the approach in an AI book I have, but there are
other ways I can go about doing the same thing, I'm sure.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to