Nested Foreach

John C johnch_atms at hotmail.com
Fri Jul 17 04:53:42 PDT 2009


Is nesting foreach statements supposed to work? I hit a problem today that I've never encountered before, even though I'm sure I've nested foreach before. Here's an example that illustrates the problem:


class Collection {

  int opApply(int delegate(ref Object) a) {
    return 0;
  }

}

Object testForeach(Collection level1, Collection level2) {
  foreach (first; level1) {
    foreach (second; level2) {
      return second;
    }
  }
  return null;
}

void main() {
  testForeach(new Collection, new Collection);
}

Error: cannot implicitly convert expression (second) of type object.Object to int

If someone else can repro this, I'll enter it into Bugzilla.

John.



More information about the Digitalmars-d mailing list