E1082: exclusive loan escapes its call

View source

An ins parameter is a loan of the caller's value for the length of the call (ADR-0020).

An ins parameter is a loan of the caller's value for the length of the call (ADR-0020). The callee never becomes its owner, so it may not return it, move it into another owner or pass it on as a dat argument. Each of these would create an owner that the caller does not know about. Reading a field or an element of the loan by value (return loan.header;, erg x = loan.header;) is the same escape; its message names the path and, for a copy type, the fix copy(value: abs loan.header) (bug #108, ADR-0124). The message names the loan. The error points at the return, the move or the argument.

Example

actus
verb keep(ins buf: Buffer) -> Buffer {
    return buf;
}

verb main() {
}
actus
verb take(dat buf: Buffer) {
}

verb pass(ins buf: Buffer) {
    take(buf: buf);
}

verb main() {
}
actus
meta copy
struct Header {
    kind: u8,
    payload_len: u16,
}

struct Parser {
    erg header: Header,
}

verb get(ins parser: Parser) -> Header {
    return parser.header;
}

verb main() {
}

Fix

Use the loan in place, for example by reading from it or passing it on as ins. Declare the parameter dat when the verb must own the value.

actus
verb keep(ins buf: Buffer) -> Int {
    return buffer_length(buffer: abs buf);
}

verb main() {
}
actus
verb take(dat buf: Buffer) {
}

verb pass(dat buf: Buffer) {
    take(buf: dat buf);
}

verb main() {
}
actus
meta copy
struct Header {
    kind: u8,
    payload_len: u16,
}

struct Parser {
    erg header: Header,
}

verb get(ins parser: Parser) -> Header {
    return copy(value: abs parser.header);
}

verb main() {
}

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