Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

VariableInitialization false positive for custom managed record with Initialize operator

Open
#468 1 comment 0 reactions 0 assignees View on GitHub

@Bazooper-blip is already working on this.

Since Sep 24, 2026.

  • #469 by @Bazooper-blip — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
compilers

Research direction

The issue is in the VariableInitialization rule. Look at the rule's code in the Java codebase, likely under src/main/java. Find where it checks for variable initialization before use. The fix needs to detect when a local variable is a custom managed record with an Initialize operator, and skip the warning. Start by understanding how the analyzer represents Delphi types and operators. Run existing tests for the VariableInitialization rule to see the current behavior.

Written by the indexing model from the issue text.

Description

enhancement rule
Prerequisites
  • This improvement has not already been suggested.
  • This improvement should not be implemented as a separate rule.
Rule to improve

Variables must be initialized before being used

Improvement description

The VariableInitialization rule reports "Initialize this variable before
using it" when a local custom managed record is passed to a routine, although
the record has an Initialize operator that assigns all its fields.

The warning also persists when the record declares and implements a Finalize
operator. In the observed case, two fields are changed after the local record
is created, and the warning appears when the record is passed as an argument.

Illustrative minimal example (using fictional names):

program ManagedRecordExample;

{$APPTYPE CONSOLE}

type
  TRequestOptions = record
    Code: Integer;
    Name: string;
    class operator Initialize(out Dest: TRequestOptions);
    class operator Finalize(var Dest: TRequestOptions);
  end;

class operator TRequestOptions.Initialize(out Dest: TRequestOptions);
begin
  Dest.Code := 0;
  Dest.Name := '';
end;

class operator TRequestOptions.Finalize(var Dest: TRequestOptions);
begin
  Dest.Name := '';
end;

procedure ProcessRequest(const Options: TRequestOptions);
begin
  WriteLn(Options.Code, ' ', Options.Name);
end;

procedure Run;
var
  Options: TRequestOptions;
begin
  Options.Name := 'Example';
  ProcessRequest(Options); // Reported as uninitialized in the observed pattern
end;

begin
  Run;
end.

The rule should account for Delphi's automatic invocation of Initialize
when assessing the subsequent use of a local custom managed record.

Rationale

A local custom managed record is initialized automatically by Delphi through
its Initialize operator. An explicit assignment solely to satisfy the rule
is therefore unnecessary. Implementing Finalize does not change the
initialization behavior or remove the warning.

This is a false positive in VariableInitialization, not a parsing problem
or the implicit-Self syntax issue addressed in #416. Ordinary records without
an Initialize operator should retain the rule's existing checks.

Documentation:
https://docwiki.embarcadero.com/RADStudio/Florence/en/Custom_Managed_Records

Dominant language
Java
Stars
160
Forks
36
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from integrated-application-development/sonar-delphi

All issues in integrated-application-development/sonar-delphi

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.