Skip to content

Cycles can be created in the exchange heap #2540

Closed
@msullivan

Description

@msullivan

The following code typechecks and runs; it causes a memory leak (and thus the runtime to trip an assert).

enum cycle {
    node({mut a: ~cycle}),
    empty
}
fn main() {
    let x = ~node({mut a: ~empty});
    // Create a cycle!
    alt check *x { node(y) { y.a <- x } };
}

It works by moving a unique pointer into the object it points to. (This code also works if the <- is a regular assignment, thanks to the last-use analysis.) Trying to log the value produces a segfault.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions