Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
June 29, 2013 Cryptic Error message with scope(failure) and AA | ||||
---|---|---|---|---|
| ||||
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. |
June 29, 2013 Re: Cryptic Error message with scope(failure) and AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anthony Goins | 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". |
June 29, 2013 Re: Cryptic Error message with scope(failure) and AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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
|
June 29, 2013 Re: Cryptic Error message with scope(failure) and AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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
|
June 29, 2013 Re: Cryptic Error message with scope(failure) and AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | 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 |
June 30, 2013 Re: Cryptic Error message with scope(failure) and AA | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra |
>
> 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.
|
Copyright © 1999-2021 by the D Language Foundation