NRefactory
NRefactory copied to clipboard
Split 'if' works wrong for OR condition
Split 'if' for (cond1 || cond2) condition should be if(cond1){} if(cond2{}
Currently: if(cond1){} else if(cond2){}
But what if both conditions are true? Then both if blocks would be executed, which is not equivalent to original "if (cond1 || cond2)". The "if" + "else if" is correct in my opinion. Do you have any example showing that "else if" is wrong?
In terms of block execution @amirhalatzi is right. But in the case of cond1 || cond2 cond2 should only be evaluated if cond1 returned false.
Consider the following example:
Result r;
if (LoadFromSource(a, out r) || LoadFromSource(b, out r))
Process(r);
Would be turned into:
Result r;
if (LoadFromSource(a, out r))
Process(r);
if (LoadFromSource(b, out r)) // what if r was already loaded from the first source?
Process(r);
Which could lead to undesired side effects...