Local variable assigned but never used, but in fact used
Original Reporter info from Mantis: hinst
-
Reporter name:
Original Reporter info from Mantis: hinst
- Reporter name:
Description:
I have the following code:
procedure TDataProvider.Execute(aStatements: TStrings);
var
executeHelper: TExecute;
begin
executeHelper.Statements := aStatements;
Transate(CreateOnProcDynArray(@executeHelper.Execute));
end;
Compiler emits a note for this code:
"GTIWS_DataProviderU.pas(196,3) Note: Local variable "executeHelper" is assigned but never used"
However I believe it is not true since I take address of method of this variable. TExecute is an object
I put a minimal example demonstrating this issue in the "Steps To Reproduce" field. This code makes the compiler emit the following message:
FPCBUG.lpr(30,3) Note: Local variable "o" is assigned but never used
When launched, prints 1
Steps to reproduce:
program FPCBUG;
{$Mode ObjFPC}
type
TMethod = procedure of object;
{ TOb }
TOb = object
Field: Integer;
procedure Go;
end;
{ TOb }
procedure TOb.Go;
begin
WriteLN(Field);
end;
procedure CallMe(const a: TMethod);
begin
a();
end;
procedure Lawl;
var
o: TOb;
begin
o.Field := 1;
CallMe(@o.Go);
end;
begin
Lawl;
end.
Additional information:
I believe this is a bug. I am not sure though
Mantis conversion info:
- Mantis ID: 26002
- OS: Windows
- Build: FPC 2.6.5
- Platform: x64
- Version: 2.6.3