This unit generates a warning that the value of frog
might be undefined even though result
is explicity set:
unit homePage;
interface
function frog(const ts, fs: string; ci: integer; const ss: string; sb, sk, sr, ay, h: integer): string;
implementation
function frog(const ts, fs: string; ci: integer; const ss: string; sb, sk, sr, ay, h: integer): string;
var
s1, s2, s3, s4, s4a, s5, s6, s7, s8: string;
m, i, j, n, sc, a, q, si, c, p, ct, f, pg, t: integer;
begin
m := 0; i := 0; j := 0; n := 0; sc := 0; a := 0; q := 0; si := 0; c := 0; p := 0; ct := 0; f := 0; pg := 0; t := 0;
s1 := ''; s2 := ''; s3 := ''; s4 := ''; s4a := ''; s5 := ''; s6 := ''; s7 := ''; s8 := '';
result := 'x';
end;
end.
The compiler (Delphi 6 build 6.240 with update pack 2) rightly warns the values assigned to the integers are never used. The original code (with much more descriptive variable names) actually sets or computes all the variables, so the only warning generated by the original code is about the function's return value; the above code has been minimized and still generates the mysterious warning. Unlike the integers, the compiler does not warn about the string variables never being used.
Just about any change to the above code (deleting or using any of the variables) makes the return value warning go away. No such luck with the original code, which always and only generates the warning the return value might be undefined.
Is this a bug in the compiler?
Is this a bug in the compiler?
Yes. There's really nothing much more to say here. It seems like all those extra local variables confuse the compiler sufficiently for it to spit out this bogus warning.