Closed BlackEdder closed 8 years ago
I think the warnings might be sane. The compiler should be able to see that the return true in the foreach is unconditional if for every overload if (__traits(compiles, getInstanceFromCustomConstructor!(T, overload, false)(JSONValue())))
evaluates to true. It then replaces the foreach with return true
, blocking return false
from being reachable. A solution not using multiple returns would be favourable so I'll look into if it's possible to use reduce instead.
Combining the fix in painlesstraits with https://github.com/BlackEdder/painlessjson/commit/9f9b94b3a47ada4ffdea16ef5dc5476c74cb9a06 makes everything pass for me on dmd 2.069. Map and reduce didn't work but this is quite elegant as well.
But if non of the if statements are correct then it should reach the return false statement or am I missing something?
On Mon, 18 Jan 2016 23:07 Pierre Krafft notifications@github.com wrote:
Combining the fix in painlesstraits with 9f9b94b https://github.com/BlackEdder/painlessjson/commit/9f9b94b3a47ada4ffdea16ef5dc5476c74cb9a06 makes everything pass for me on dmd 2.069. Map and reduce didn't work but this is quite elegant as well.
— Reply to this email directly or view it on GitHub https://github.com/BlackEdder/painlessjson/issues/49#issuecomment-172677446 .
Yes if there are no valid constructors the function reaches the return false. But this is a compile time function so the foreach gets unrolled to just some if true return true; if false return true;
, and thereby blocks the return false. Using an accumulator solves this by having just one return statement.
The unrolling makes sense. Thanks for the explanation. Will wait for @msoucy to merge and increment painlesstraits' version number, and then merge imports.
The branch is ready for version bump and merge!
Thanks @Zalastax and @msoucy
@msoucy and @Zalastax I tried to compile painlessjson with the newest version, but get the following error (see travis failure for imports branch):
The statement looks reachable to me, what do you guys think? Compiler bug?