Thread overview
Phobos unit tests, unreadable code
Jun 12, 2013
Jacob Carlborg
Jun 12, 2013
monarch_dodra
Jun 12, 2013
Jacob Carlborg
June 12, 2013
I'm merging the orange (std.serialization) unit tests with the test of Phobos. I hit a problem. I'm getting a warning about unreadable code but it's clear the code is reachable in some cases because there's a static-if involved. The unit tests won't run if there's a warning. How can we solve this?

-- 
/Jacob Carlborg
June 12, 2013
On Wednesday, 12 June 2013 at 08:49:36 UTC, Jacob Carlborg wrote:
> I'm merging the orange (std.serialization) unit tests with the test of Phobos. I hit a problem. I'm getting a warning about unreadable code but it's clear the code is reachable in some cases because there's a static-if involved. The unit tests won't run if there's a warning. How can we solve this?

The problem is that there must be a static if branch that is shortcicuiting the code, right? Eg:

unittest
{

    static if (somecondition) return;

    unreachable_code
}

The compiler error (AFAIK) for "unreachable code" is not generic to the code, but only appears for the specific types that makes the unreachable_code actually unreachable. I've hit this a couple of times in algorithm's unittests.

The workaround is usally to use static else and/or assert(0), and to make sure that regardless of types, there is never any code inserted that could be un-used.

Do you have a link to the actual problem?
June 12, 2013
On 2013-06-12 10:55, monarch_dodra wrote:

> Do you have a link to the actual problem?

This, for example:

https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L1217

I could probably add an else.

-- 
/Jacob Carlborg