Skip to content

The old construct does not respect the function requirements #3359

@celinval

Description

@celinval

I tried this code:

#[kani::requires(val < i32::MAX)]
#[kani::ensures(|result| *result == old(val + 1))]
pub fn next(mut val: i32) -> i32 {
    val + 1
}

#[kani::proof_for_contract(next)]
pub fn check_next() {
    // Placing the restriction before calling makes the problem go away.
    // let _ = next(kani::any_where(|val: &i32| *val < i32::MAX));
    let _ = next(kani::any());
}

using the following command line invocation:

kani -Z function-contracts next.rs

with Kani version:

I expected to see this happen: Verification succeeded

Instead, this happened: Verification failed due to overflow:

Failed Checks: attempt to add with overflow
 File: "next.rs", line 2, in next_check_53aede

Metadata

Metadata

Assignees

Labels

Z-ContractsIssue related to code contracts[C] BugThis is a bug. Something isn't working.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions