Skip to content
This repository

"let _ = foo();" is differently effectful from just "foo();" #2735

Closed
bblum opened this Issue June 27, 2012 · 4 comments

2 participants

Ben Blum Tim Chevalier
Ben Blum
Collaborator
bblum commented June 27, 2012

See #2734. In that sample code, which segfaults, removing the characters "let _ =" causes it to no longer segfault. No idea why; maybe it causes it to optimise away the destructor call?

Tim Chevalier
Collaborator

I'll see if this is still a bug now.

Tim Chevalier catamorphism closed this issue from a commit July 10, 2012
Tim Chevalier Test for issue 2735
This probably doesn't test the actual bug, but the fix for
issue 2734 probably camouflages the actual bug (since the
effect of the #2734 test case is now "do nothing observable"
rather than "segfault").

Closes #2735
7b4190d
Tim Chevalier catamorphism closed this in 7b4190d July 10, 2012
Ben Blum bblum reopened this August 01, 2012
Ben Blum
Collaborator

This is still in the air. The following code prints "First" then "Second", but without the let _ =, it prints "Second" then "First".

class defer {
    f: fn@();
    new(f: fn@()) {
        self.f = f;
    }   
    drop { self.f(); }
}

fn main() {
    let _ = do defer {
        #error["Second"];
    };  
    #error["First"];
}

I'm not sure if the answer is "Well, too bad, there are no guarantees on when destructors get run", but I want to add this defer thing to libcore, and can't in good conscience as long as its behaviour is unpredictable.

Tim Chevalier
Collaborator

I have a fix for this, which I'm testing. However, for reference, what you want to do to get the behavior that bblum actually wanted was to write:

let _x = do ...

which means the destructor for the RHS won't run until the end of the enclosing scope, since _x is a perfectly cromulent identifier.

Tim Chevalier
Collaborator

My opinion is that let _ = e; should behave just like e; Feel free to argue about it, but for now I'm closing this.

Tim Chevalier catamorphism closed this August 08, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.