Thread overview | |||||
---|---|---|---|---|---|
|
September 22, 2020 why is this flagged as poor style? | ||||
---|---|---|---|---|
| ||||
The style checker for phobos flags this code: static if (!is(typeof(unaryFun!fun(r.front)) == Flag!"each")) cast(void) unaryFun!fun(r.front); else if (unaryFun!fun(r.front) == No.each) return No.each; with "Mismatched static if. Use 'else static if' here." But in fact the intention is to execute a run-time `if` on the `else` branch of the `static if`. Is this worth fixing? |
September 22, 2020 Re: why is this flagged as poor style? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 9/22/20 5:35 PM, Andrei Alexandrescu wrote:
> The style checker for phobos flags this code:
>
> static if (!is(typeof(unaryFun!fun(r.front)) == Flag!"each"))
> cast(void) unaryFun!fun(r.front);
> else
> if (unaryFun!fun(r.front) == No.each) return No.each;
>
> with "Mismatched static if. Use 'else static if' here."
>
> But in fact the intention is to execute a run-time `if` on the `else` branch of the `static if`.
>
> Is this worth fixing?
>
I think it needs braces (I'd do them for both blocks).
When you are mixing static if and if (or version etc.), make it very clear the difference.
-Steve
|
September 22, 2020 Re: why is this flagged as poor style? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 22 September 2020 at 21:50:11 UTC, Steven Schveighoffer wrote:
> I think it needs braces (I'd do them for both blocks).
The D-Scanner check that's begin discussed here has a unit test checking that adding braces will silence the warning.
|
Copyright © 1999-2021 by the D Language Foundation