DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B6009: use of an object while it is borrowed

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

A borrower (an object of an anonymous access type) takes the structure an owner owns for a while, to change it in place. While the borrower lives, the owner cannot be used at all, neither read nor written: the borrower may be changing what it would read. Where the borrower's scope ends, the owner has the structure back, with the changes made through the borrower.

Example (Vada)

   procedure Bump (L : in out List) with Pre => L /= null is
      B : constant access Node := L;   --  B borrows L
   begin
      B.Value := L.Value + 1;          --  L is used while B lives
   end Bump;

Example (Varc)

    fn bump(l: inout List) requires l != null {
        let b: *Node = l;     // b borrows l
        b.Value = l.Value + 1;   // l is used while b lives
    }

What to do

Use the structure through the borrower (B.Value := B.Value + 1;), or use the owner after the borrower's scope ends (declare the borrower in a block).

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.