creusot icon indicating copy to clipboard operation
creusot copied to clipboard

Creusot panics when using `gh!` inside a closure

Open arnaudgolfouse opened this issue 1 year ago • 3 comments

This code crashes creusot with "called Option::unwrap() on a None value":

fn f() {
    let x = 1;
    let clos = || {
        let y = gh!(x);
    };
}

It seems this is because creusot assumes a variable captured in gh! is always defined in the enclosing function.

arnaudgolfouse avatar Feb 22 '24 16:02 arnaudgolfouse

Maybe the following is enough

// creusot/src/translation/specification.rs:125
- Place(p) => p.as_local().unwrap(),
+ Place(p) => p.local,

Am I missing something ?

arnaudgolfouse avatar Feb 22 '24 16:02 arnaudgolfouse

Have you tested?

I haven't tested anything, but it seems to me that p should be the closure itself, with the projection being the the captured variable. So no, I would rather bet (but I'm unsure) there is something more subtle to be done here.

jhjourdan avatar Feb 22 '24 16:02 jhjourdan

Yea it is that line but that's not going to be a correct fix, the purpose of that line is to identify the captures of ghost closures, which need to be erased and I think it glitches out for "ghost captures".

xldenis avatar Feb 22 '24 19:02 xldenis

Fixed by #1106

arnaudgolfouse avatar Sep 23 '24 13:09 arnaudgolfouse