[Issue 2192] Returning element in an AA of AAs during nested foreach generates compiler error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 4 00:22:31 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2192





------- Comment #1 from business3 at twistedpairgaming.com  2008-07-04 02:22 -------
Changing the function's return type to something else, like 'bool' also
eliminates the problem.

Making the return statement conditional (ex "if(f.var == 1) return null;") does
NOT solve to problem.

If you need to return f, the following workaround does work (although it will
result in extra unnecessary iterations):

Foo Bar()
{
        Foo ret = null;
        foreach(Foo[char] array; jaggedArray)
        {
                foreach(Foo f; array)
                {
                        if( /* whatever you need */ )
                        {
                                if(ret == null)
                                        ret = f;
                                break;
                        }
                }
        }
        return ret;
}


-- 



More information about the Digitalmars-d-bugs mailing list