E1066: returned view has no single abs origin

View source

A verb that returns -> abs hands out a view of something.

A verb that returns -> abs hands out a view of something. ADR-0021 requires the view to come from exactly one place, which must be an abs parameter of the same verb, so the caller knows which owner it borrows from. The compiler rejects an abs return when the verb has more than one non-scalar abs parameter, when the returned value comes from a local, and when it mixes several origins or has an unknown one. The message gives the reason. The error points at the returned expression.

Example

actus
verb pick(abs a: Buffer, abs b: Buffer) -> abs Buffer {
    return a;
}

verb main() {
}
actus
verb make(abs a: Buffer) -> abs Buffer {
    erg local: Buffer = Buffer[4];
    return local;
}

verb main() {
}

Fix

Take one abs parameter and return a view of it. Do not return a view of a value that the verb creates, because it would not outlive the call.

actus
verb pick(abs a: Buffer) -> abs Buffer {
    return a;
}

verb main() {
}

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