E1065: one call borrows the same value twice

View source

An ins argument is an exclusive loan of its owner for the length of the call (ADR-0020).

An ins argument is an exclusive loan of its owner for the length of the call (ADR-0020). No other argument of that call may name the same owner, because the callee would then see one value through two paths and could change it while the other path looks at it. The rule covers two ins arguments and an ins next to an abs argument. Different fields of one struct do not clash. The message names the owner. The error points at the second argument.

Example

actus
verb fill(ins first: Buffer, ins second: Buffer) {
}

verb main() {
    erg data: Buffer = Buffer[4];
    fill(first: ins data, second: ins data);
}
actus
verb fill(ins first: Buffer, abs second: Buffer) {
}

verb main() {
    erg data: Buffer = Buffer[4];
    fill(first: ins data, second: abs data);
}

Fix

Pass distinct owners, or split the work into two calls, because a loan ends when its call returns.

actus
verb fill(ins first: Buffer, ins second: Buffer) {
}

verb main() {
    erg data: Buffer = Buffer[4];
    erg other: Buffer = Buffer[4];
    fill(first: ins data, second: ins other);
}
actus
verb fill(ins first: Buffer) {
}

verb main() {
    erg data: Buffer = Buffer[4];
    fill(first: ins data);
    fill(first: ins data);
}

Run actus explain E1065 in your terminal to read this entry offline. Browse Ownership & types or all error codes.