Nested Foreach
Nick Sabalausky
a at a.a
Fri Jul 17 11:31:35 PDT 2009
"John C" <johnch_atms at hotmail.com> wrote in message
news:h3poo6$13j4$1 at digitalmars.com...
> 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.
I came across a problem much like that a while back. Does this describe your
problem?:
http://d.puremagic.com/issues/show_bug.cgi?id=2192
It looks like you're using iterable objects instead of AAs though. If you
think it seems like basically the same bug, maybe update the ticket to
indicate the problem is more general than just AAs.
More information about the Digitalmars-d
mailing list