Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal error for postcondition that uses blocked self #418

Open
fpoli opened this issue Feb 19, 2021 · 1 comment
Open

Internal error for postcondition that uses blocked self #418

fpoli opened this issue Feb 19, 2021 · 1 comment
Labels
error-reporting Something needs to be fixed in the error reporting

Comments

@fpoli
Copy link
Member

fpoli commented Feb 19, 2021

Prusti reports an internal error ("generating fold-unfold Viper statements failed") when verifying the following program.

The reason is that a postcondition tries to use self while it's blocked by a mutable reference that is returned. The correct way is to write the postcondition using a pledge, but the error message is not helpful.

use std::marker::PhantomData;
use prusti_contracts::*;

pub struct Foo<T>(PhantomData<T>);

impl<T> Foo<T> {
    #[pure]
    #[trusted]
    pub fn len(&self) -> usize {
        unimplemented!()
    }

    #[trusted]
    pub fn get_mut_baz(&mut self, idx: usize) -> &mut T {
        unimplemented!()
    }

    #[ensures(self.len() == old(self.len()) - 1)] // Incorrect
    pub fn get_mut_bar(&mut self, idx: usize) -> &mut T {
        self.get_mut_baz(idx)
    }
}

fn main() {}
@fpoli fpoli added the error-reporting Something needs to be fixed in the error reporting label Feb 19, 2021
@fpoli
Copy link
Member Author

fpoli commented Jul 5, 2023

Smaller example:

use prusti_contracts::*;

#[ensures(value === value)]
pub fn get_mut(
    value: &mut i32
) -> &mut i32 {
    value
}
[Prusti internal error] Prusti encountered an unexpected internal error
...
Details: cannot generate fold-unfold Viper statements. The required permission Acc(old[pre](_1.val_ref).val_int, read) cannot be obtained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-reporting Something needs to be fixed in the error reporting
Projects
None yet
Development

No branches or pull requests

1 participant