Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 03, 2013 Statement is unreachable error | ||||
---|---|---|---|---|
| ||||
I reach this error all the time. When debugging for instance, I may want to stick a throw in the middle of some code, or whatever, and get into it, have to go back to the code, comment bunch of stuff, go back to compile. This is something that is obviously important to have, but I think to have it by default is really annoying. In addition, it tends to kick in when using static if. See sample code below : uint foo() { static if(condition) { return 0; } // Do some computation. return value; } Now, if you want that piece of code to compile, you got to stick the whole function body into an else, and it really make the code unreadable sometime when you got static ifs within other static ifs. Can we at least disable the feature for termination of control flow that belongs to different compile time scope ? |
June 03, 2013 Re: Statement is unreachable error | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Monday, 3 June 2013 at 14:53:23 UTC, deadalnix wrote:
> I reach this error all the time. When debugging for instance, I may want to stick a throw in the middle of some code
I have the same problem, sometimes for testing purposes (exactly
for debugging) I'd like to return early or throw, but then I get
compiler errors.
|
June 03, 2013 Re: Statement is unreachable error | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Monday, 3 June 2013 at 14:57:13 UTC, Andrej Mitrovic wrote:
> On Monday, 3 June 2013 at 14:53:23 UTC, deadalnix wrote:
>> I reach this error all the time. When debugging for instance, I may want to stick a throw in the middle of some code
>
> I have the same problem, sometimes for testing purposes (exactly
> for debugging) I'd like to return early or throw, but then I get
> compiler errors.
It would be nice to have a compiler switch that turns off these errors.
|
June 04, 2013 Re: Statement is unreachable error | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Monday, 3 June 2013 at 15:21:15 UTC, John Colvin wrote:
> On Monday, 3 June 2013 at 14:57:13 UTC, Andrej Mitrovic wrote:
>> On Monday, 3 June 2013 at 14:53:23 UTC, deadalnix wrote:
>>> I reach this error all the time. When debugging for instance, I may want to stick a throw in the middle of some code
>>
>> I have the same problem, sometimes for testing purposes (exactly
>> for debugging) I'd like to return early or throw, but then I get
>> compiler errors.
>
> It would be nice to have a compiler switch that turns off these errors.
One of the problem's _I_ have been able to observe, and which is particularly problematic (IMO), is when it happens only in release.
For example:
foreach(e; range)
if(e==1)
return 1;
return 0;
Imagine now "range" happens to be an infinite range. Now, return 0 will never be reached. Unfortunately, the compiler only sees this in release.
This makes unittesting problematic, since there have been a few observed cases of unittests that passed, but would have failed to compile in a production environment.
|
Copyright © 1999-2021 by the D Language Foundation