E1149: a holder field holds a value of the holder's own arena

View source

A struct that holds an arena releases it itself (ADR-0130).

A struct that holds an arena releases it itself (ADR-0130). A field of that struct cannot hold a value placed in the same arena, or a view of such a value: the holder would contain a reference into storage that it releases, and the release order of its fields could not keep both valid. The error points at the field initializer of a struct literal, or at the assignment that stores the value into the field. The message names the field and the holder.

A value placed in another arena is a different case. A struct literal cannot mix the arena it takes with a value of another arena (E1078), and a field assignment of a value of another arena follows the existing provenance rules.

Example

actus
struct Node {
    value: Int,
}

struct Scene {
    erg nodes: Arena[64],
    erg first: Node,
}

verb main() {
    erg arena: Arena[64] = Arena[64]();
    erg node = place(arena: ins arena, value: Node { value: 1, });
    erg scene = Scene { nodes: arena, first: node, };
}
actus
struct Node {
    value: Int,
}

struct Scene {
    erg nodes: Arena[64],
    erg first: Node,
}

verb main() {
    erg scene = Scene { nodes: Arena[64](), first: Node { value: 0, }, };
    erg node = place(arena: ins scene.nodes, value: Node { value: 1, });
    scene.first = node;
}

Fix

Store a value that is not placed in the holder's arena, or keep a result computed from the placed value, such as its Int field.

actus
struct Node {
    value: Int,
}

struct Scene {
    erg nodes: Arena[64],
    erg first: Node,
}

verb main() -> Int {
    erg scene = Scene { nodes: Arena[64](), first: Node { value: 0, }, };
    erg node = place(arena: ins scene.nodes, value: Node { value: 1, });
    scene.first = Node { value: node.value, };
    return scene.first.value;
}

Run actus explain E1149 in your terminal to read this entry offline. Browse Modules & rules or all error codes.