org.sonar.l10n.delphi.rules.community-delphi.RoutineResultAssigned.html Maven / Gradle / Ivy
The newest version!
Why is this an issue?
Functions should not leave their result uninitialized, as their return value will then be
undefined.
This also includes out
parameters, which are designed to populate an uninitialized
variable outside the routine.
How to fix it
For a function, ensure that Result
is initialized by the end of every branch:
function GetWeapon(Ranged: Boolean): TWeapon;
begin
if Ranged then begin
Result := TBow.Create;
end;
end;
function GetWeapon(Ranged: Boolean): TWeapon;
begin
if Ranged then begin
Result := TBow.Create;
end
else begin
Result := TSword.Create;
end;
end;
Ensure that all out
parameters are initialized by the end of every branch:
procedure GetOutfit(PersonName: string; out Shirt: TShirt; out Pants: TPants);
begin
if (PersonName <> '') then begin
Shirt := GetShirt(PersonName);
Pants := GetPants(PersonName);
end;
end;
procedure GetOutfit(PersonName: string; out Shirt: TShirt; out Pants: TPants);
begin
if (PersonName <> '') then begin
Shirt := GetShirt(PersonName);
Pants := GetPants(PersonName);
end
else begin
Shirt := nil;
Pants := nil;
end;
end;
Resources
© 2015 - 2024 Weber Informatics LLC | Privacy Policy