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

Support for old(..) expressions in loop invariants #1500

Open
fpoli opened this issue Feb 29, 2024 · 0 comments
Open

Support for old(..) expressions in loop invariants #1500

fpoli opened this issue Feb 29, 2024 · 0 comments
Labels
bug Something isn't working error-reporting Something needs to be fixed in the error reporting

Comments

@fpoli
Copy link
Member

fpoli commented Feb 29, 2024

The following program makes Prusti raise an internal error, because currently old(..) expressions are only allowed in postconditions.

use prusti_contracts::*;

#[ensures(a % result == 0)]
#[ensures(b % result == 0)]
fn euklid(a: u32, b: u32) -> u32 {
    let mut c = 0;
    if a == 0 {
        if b == 0 {
            return 1;
        } else {
            return b;
        }
    } else {
        let mut a = a;
        let mut b = b;
        while b != 0 {
            body_invariant!(a % c == 0 && b % c == 0 && old(a) % a == 0 && old(b) % b == 0);
            c = a % b;
            a = b;
            b = c;
        }
        return a;
    }
}

fn main() {}

The suggested workaround is to store a copy of the arguments in local variables at the beginning of the function: let old_a = a; etc.

@fpoli fpoli added bug Something isn't working error-reporting Something needs to be fixed in the error reporting labels Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working error-reporting Something needs to be fixed in the error reporting
Projects
None yet
Development

No branches or pull requests

1 participant