Of course this was not what the emitting code actually looked like. What it actually looked like was something like:

void Emit(Class c){ if (c == null || c.Emitted) return; // don’t emit twice! Emit(c.BaseClass); Emit(c.OuterClass); // If somehow Emit was called on this class before our outer class, then // we just caused ourselves to be emitted when we emitted the outer class. // (The outer class emits its inner classes, ie, the current // class, before it returns.) // If we are already emitted then we have no more work to do. if (c.Emitted) { Debug.Assert(c.OuterClass != null && c.OuterClass.Emitted); return; } ReallyEmit(c); c.Emitted = true; foreach(Class i in c.InnerClasses) Emit(i);}

This algorithm is correct. However, the comment and the assertion are not correct. (This is why I was looking at this code in the first place, because the assertion was firing. I fixed it by updating the comment and removing the assertion.)

Can you find a legal set of C# classes which are correctly emitted but cause the assertion to fire?