DFA gives bogus message about dynamic arrays being initialized
Original Reporter info from Mantis: Hixie
-
Reporter name: Ian Hickson
Original Reporter info from Mantis: Hixie
- Reporter name: Ian Hickson
Description:
In the example below, the DFA code says that a procedures 'var' argument might be uninitialised when it's passed to another function that takes a 'var' argument (see case Bar below). This makes no sense; the whole point of 'var' arguments is that they are initialised by the caller.
It also does the same with a global variable (Baz case below). In the case of the global, the variable is guaranteed to be initialised to zero. However, this latter case may be intentional; see issue 24601 which is similar but about strings.
{$OPTIMIZATION DFA}
{$HINTS ON}
program test;
type
TIntArray = array of Integer;
procedure Reset(var Foo: TIntArray);
begin
SetLength(Foo, 0);
end;
procedure Foo(var Bar: TIntArray);
begin
Reset(Bar); // Hint: Local variable "Bar" does not seem to be initialized
end;
var
Baz: TIntArray;
begin
Foo(Baz); // Hint: Local variable "Baz" does not seem to be initialized
end.