Not all code paths return a value

Properties
PC0038 Info Usage Code Fix Ignore Obsolete

Procedures with a return type must produce a value on every reachable path. If one branch falls through without returning a value, AL can end up returning an implicit default value (0, false, empty text), which hides logic bugs and makes behavior harder to reason about.

This rule flags declarations where not all code paths return a value.

Example

The following procedure misses a return value when the condition is false:

procedure GetAmount(IncludeVat: Boolean): Decimal
begin
    if IncludeVat then
        exit(AmountInclVat);
end;

Return a value on all paths:

procedure GetAmount(IncludeVat: Boolean): Decimal
begin
    if IncludeVat then
        exit(AmountInclVat)
    else
        exit(AmountExclVat);
end;

When the diagnostic is reported

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

  • The declaration is a procedure with an explicit return type
  • At least one reachable path can end without returning a value
  • The declaration is not marked with TryFunction

Triggers are intentionally excluded from this rule, even when they declare a return type.

Exception

Paths that end with Error(...) are accepted:

procedure GetAmount(IncludeVat: Boolean): Decimal
begin
    if IncludeVat then
        exit(AmountInclVat)
    else
        Error('Prices without VAT are not supported.');
end;

A named return variable passed to a var parameter, or used as the receiver of a call, counts as assigned:

procedure BuildGreeting() Greeting: Text
begin
    GetGreeting(Greeting);
end;

local procedure GetGreeting(var GreetingText: Text)
begin
    GreetingText := 'Hello';
end;

procedure FindCustomer(CustomerNo: Code[20]) Customer: Record Customer
begin
    Customer.Get(CustomerNo);
end;

Passing it by value (without var) does not count.

See also