Skip to content

"Warning: Variable "..." of a managed type does not seem to be initialized" on local variables even when using management operators

Summary

If you define a record with an Initialize class operator, a variable of that type will be flagged as uninitialized if you first use it by passing it to a procedure, even though it's definitely initialized.

Steps to reproduce

Compile this:

{$MODE OBJFPC}
{$MODESWITCH ADVANCEDRECORDS+}
type
   TTest = record
      X: Integer;
      class operator Initialize(var Value: TTest);
   end;

class operator TTest.Initialize(var Value: TTest);
begin
   Value.X := 123;
end;

var
   A: TTest;
begin
   Writeln(A.X); // prints 123
end.

You will get this warning:

test.pas(17,12) Warning: Variable "A" of a managed type does not seem to be initialized

...even though A.X is 123.

System Information

  • Operating system: Linux
  • Processor architecture: x86-64
  • Compiler version: trunk compiled on 2025/07/03
  • Device: Computer
Edited by Ian Hickson
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information