DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B6008: value still moved at the end of a loop iteration

Catalog status: active. Default severity: error. Stable name: moved-in-loop. Family: Ownership and finalization.

Every iteration of a loop must begin in the same ownership state, so an iteration must not end with a part moved out that was not already moved when the loop began. Otherwise the next iteration would start with a moved value it may not read.

Example (Vada)

   N : List;
begin
   while L /= null loop
      N := L.Next;
      L.Next := R;
      R := L;
      L := N;   --  moves N, which stays moved when the iteration ends
   end loop;

Example (Varc)

    var n: List;
    while l != null {
        n = l.next;
        l.next = r;
        r = l;
        l = n;   // moves n, which stays moved when the iteration ends
    }

What to do (Vada)

Assign the moved object again before the iteration ends (null, or what it should own), or declare it inside the loop so that it dies there:

   while L /= null loop
      declare
         N : List := L.Next;
      begin
         L.Next := R;
         R := L;
         L := N;
      end;
   end loop;

What to do (Varc)

Assign the moved object again before the iteration ends (null, or what it should own), or declare it inside the loop so that it dies there:

    while l != null {
        var n: List = l.next;
        l.next = r;
        r = l;
        l = n;
    }

Regression source and further reading

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

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