Cryptic Error message with scope(failure) and AA

monarch_dodra monarchdodra at gmail.com
Sat Jun 29 14:26:33 PDT 2013


On Saturday, 29 June 2013 at 20:45:12 UTC, Anthony Goins wrote:
> Is this known?
> I've heard there are many problems with associative arrays.
>
> dmd 2.063
>
> ---
> module scopefailtest;
>
> int[char] AAarray;
>
> void main(string[] args)
> {
>      AAarray = ['a':1, 'b':2, 'c':3];
>      foreach(aa; AAarray)
>      {
>           scope(failure)continue;
>           aa = 32;
>      }
> }
> ---
>
> dmd output
> Error: cannot implicitly convert expression (0) of type int to 
> void
>
>
> Works without scope(failure)
> Works with non Associative Array
>
> No helpful description.
> No file or line number.
> Very hard to find.

Seems like there are several levels of "wrong" actually: What do 
you expect "scope(failure)continue" to do exactly?

It compiles, but it doesn't make much sense?

When I run this code:
--------
void main(string[] args)
{
      foreach(aa; 0 .. 3)
      {
           scope(failure){writeln("error");continue;}
           writeln(aa);
           throw new Exception("");
      }
}
--------

I get:
--------
0
error
1
error
2
error
--------

Which is wrong, since a scope(failure) is not supposed to "catch" 
the exception. In this case, the "continue" short-circuits the 
compiler generated "rethrow".

DMD is on to something, because if you replace failure with 
"exit" or "success", then it complains with: "Error: continue is 
not inside a loop".


More information about the Digitalmars-d-learn mailing list