Avoid mixing exit() and named return variable assignments

Properties
LC0097 Info Usage Code Fix Ignore Obsolete

In procedures (and triggers) with a named return variable, use one return style consistently:

  • Assign to the named return variable and let the declaration end normally, or
  • Return using exit(<value>)

Mixing both styles in the same declaration makes control flow harder to follow and increases the risk of accidental default returns.

This diagnostic is disabled by default. Enable LC0097 in your ruleset when you want to enforce a single return style.

Example

This procedure mixes both styles:

procedure Compute(UseFallback: Boolean) Result: Integer
begin
    Result := 10;

    if UseFallback then
        exit(20);
end;

Use one style consistently. Example using only the named return variable:

procedure Compute(UseFallback: Boolean) Result: Integer
begin
    Result := 10;

    if UseFallback then
        Result := 20;
end;

Alternative style using only exit(<value>):

procedure Compute(UseFallback: Boolean): Integer
begin
    if UseFallback then
        exit(20)
    else
        exit(10);
end;

When the diagnostic is reported

The rule is reported when all of the following are true:

  • The declaration has a named return variable
  • There is at least one assignment to that named return variable
  • There is at least one exit statement
  • The declaration is not marked with TryFunction

See also