DFA gives bogus message: Hint: Local variable "$self" does not seem to be initialized
Original Reporter info from Mantis: Hixie
-
Reporter name: Ian Hickson
Original Reporter info from Mantis: Hixie
- Reporter name: Ian Hickson
Description:
The compiler outputs the hint "Local variable "$self" does not seem to be initialized" for the following test on the given lines. It seems to be any time you try to mutate (as opposed to read) an object's member variable.
{$MODE OBJFPC}
{$HINTS ON}
{$OPTIMIZATION DFA}
program test;
type
TTest1 = class
FArray: array of record end; // or AnsiString
procedure TestMethod();
end;
procedure TTest1.TestMethod();
begin
SetLength(FArray, 0); // Hint: Local variable "$self" does not seem to be initialized
end;
type
TTest2 = class
FString: AnsiString; // or dynamic array
procedure TestMethod();
end;
procedure TTest2.TestMethod();
begin
FString := Default(AnsiString); // Hint: Local variable "$self" does not seem to be initialized
end;
type
TTest3 = class
FValue: Integer;
procedure TestMethod(var Value: Integer);
end;
procedure TTest3.TestMethod(var Value: Integer);
begin
TestMethod(FValue); // Hint: Local variable "$self" does not seem to be initialized
end;
begin
end.
I've also seen it with Move(), in constructors, on calls to procedures of type helpers for member variables of type AnsiString, and on the Self variable of AnsiString type helpers. As far as I can tell, this specific warning with the value "$self" is never valid.
Mantis conversion info:
- Mantis ID: 25914
- OS: Linux
- Build: trunk 2014/03/18
- Platform: x86_64
- Version: 2.7.1
- Fixed in version: 3.1.1
- Fixed in revision: 29636 (#932b6831)