DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B6010: change to an object while it is observed

Catalog status: active. Default severity: error. Stable name: observed-object-changed. Family: Ownership and finalization.

An observer (an object of an anonymous access constant type) reads the structure an owner owns without taking it. While the observer lives, the owner is read-only: nothing may assign it, move out of it, or pass it to a call that can change it, so that what the observer reads stays what the owner holds.

Example (Vada)

   procedure Touch (L : in out List) is
      X : constant access constant Node := L;   --  X observes L
   begin
      L := null;                                --  L changes while X lives
   end Touch;

Example (Varc)

    fn touch(l: inout List) {
        let x: *const Node = l;   // x observes l
        l = null;                 // l changes while x lives
    }

What to do

Change the owner after the observer's scope ends (declare the observer in a block), or, to change the structure in place, use a borrower (an anonymous access object) instead.

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.