www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Cryptic Error message with scope(failure) and AA

reply "Anthony Goins" <neontotem gmail.com> writes:
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.
Jun 29 2013
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
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".
Jun 29 2013
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Saturday, June 29, 2013 23:26:33 monarch_dodra wrote:
 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".
I thought that there was a bug report on that (probably suggesting that the compiler make such a continue illegal), but I can't find it right now. - Jonathan M Davis
Jun 29 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
Jonathan M Davis:

 I thought that there was a bug report on that (probably 
 suggesting that the
 compiler make such a continue illegal), but I can't find it 
 right now.
If you can't find it, it's better to file it because it's better to have a bug two times in Bugzilla than no times. Bye, bearophile
Jun 29 2013
prev sibling next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 06/29/2013 02:26 PM, monarch_dodra wrote:

 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".
Hmmm... 'continue' and others are disallowed only for scope(exit) and scope(success): http://dlang.org/statement.html#ScopeGuardStatement "A scope(exit) or scope(success) statement may not exit with a throw, goto, break, continue, or return; nor may it be entered with a goto." Ali
Jun 29 2013
prev sibling parent "Anthony Goins" <neontotem gmail.com> writes:
 Seems like there are several levels of "wrong" actually: What 
 do you expect "scope(failure)continue" to do exactly?
I was reading an array of files (Document[string]). Stuck the scope(failure)continue in late at night apparently to skip reading files that no longer exist. Forgot about it. Still don't remember doing it. Next day tried to build my project (30+ files). I had no clue what was going on given the error message. The problem for me was not the error itself but the message. Thanks for the reply. Didn't realize there was a problem with 'continue' from a scopeguard.
Jun 29 2013