Skip to content

Nondeterministic behavior when referencing a closure more than once #5783

Closed
@bstrie

Description

@bstrie

This program works as expected:

fn main() {
    let a = |x:int| { |y:int| -> int { x + y } };
    let b = a(2);
    //println(int::to_str(a(2)(3)));
    println(int::to_str(b(3)));  // 6
}

Uncomment that line and something goofy happens:

fn main() {
    let a = |x:int| { |y:int| -> int { x + y } };
    let b = a(2);
    println(int::to_str(a(2)(3)));  // 6
    println(int::to_str(b(3)));  // completely random number
}

The second print will be a different number every time it is run. This feels quite dangerous.

And if you try to use error!(b(3)), even in the first program, you get a segfault. But that might be a separate bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-type-systemArea: Type systemE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions