DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B5109: subprogram variant might not make progress

Catalog status: active. Default severity: error. Stable name: subprogram-variant. Family: Contracts and termination.

Subprogram_Variant names values of the parameters that must move in the stated direction (Decreases or Increases) from a call to each recursive call it makes. Since the values are bounded by their subtypes, the recursion then ends. The prover found a recursive call whose actuals do not make the variant move.

Example (Vada)

   function Sum (N : Natural) return Natural
     with Subprogram_Variant => (Decreases => N),
          Pre => N <= 100
   is
   begin
      if N = 0 or N = 100 then
         return 0;
      else
         return Sum (N + 1);   --  N increases
      end if;
   end Sum;

Example (Varc)

    fn sum(n: Natural) -> Natural
        decreases n
        requires n <= 100
    {
        if n == 0 || n == 100 {
            return 0;
        } else {
            return sum(n + 1);   // n increases
        }
    }

What to do (Vada)

State the variant in the direction the recursion really goes (Increases => N here), or fix the recursive call.

What to do (Varc)

State the variant in the direction the recursion really goes (@Subprogram_Variant(Increases => n) here), or fix the recursive call.

Regression source and further reading

Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.

See contracts and termination, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.