Issue
Pretty sure the warning means that I declared a variable that I never used elsewhere but I'm almost positive I am using this variable.
The line it highlights is:
return fitIndex = ++i;
Yet if I remove the ++i
my code behaves erroneously.
If I do this instead:
fitIndex = ++i;
return fitIndex;
It gives no warnings.
Is there some interaction here with the return statement I'm missing? Doesn't it increment i
first, then assign it to fitIndex
, and then returns the value?
It doesn't affect my code at all, but just curious.
Solution
There doesn't seem to be any purpose to fitIndex
(you never access the value, since you return immediately). In other words, the compiler thinks
return fitIndex = ++i;
can be replaced by
return ++i;
tl;dr you can remove fitIndex
.
Answered By - Elliott Frisch