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

Clarify failing postcondition of trait method #13

Open
fpoli opened this issue Mar 17, 2020 · 2 comments
Open

Clarify failing postcondition of trait method #13

fpoli opened this issue Mar 17, 2020 · 2 comments
Labels
enhancement New feature or request error-reporting Something needs to be fixed in the error reporting

Comments

@fpoli
Copy link
Member

fpoli commented Mar 17, 2020

In the following program Prusti identifies a verification error as expected: the method implementation A::bar does not specify a postcondition, so it gets by default the result > 10 from the trait definition, but the implementation returns 0. The error message currently points to the failing postcondition in the trait definition, but this is ambiguous because there are multiple types that implement that trait, and it's not immediately clear which of them is involved in the error.

The error message should use as primary span the fn baz() -> usize in the method implementation, excluding the method's body { .. } to keep the span short and readable.

extern crate prusti_contracts;

trait Foo {
    #[ensures="result > 10"] // Failing postcondition. The verification error is currently reported here.
    fn bar() -> usize;
}

struct A;

impl Foo for A {
    fn bar() -> usize { // Bad implementation. The verification error should be reported here.
        0
    }
}

struct B;

impl Foo for B {
    fn bar() -> usize { // Correct implementation
        100
    }
}

fn main(){}
@fpoli fpoli added the enhancement New feature or request label Mar 17, 2020
@fpoli fpoli added the to-check label Mar 1, 2021
@JonasAlaif
Copy link
Contributor

This is still an issue:

use prusti_contracts::*;

trait Foo {
    #[ensures(result > 10)] // Failing postcondition. The verification error is currently reported here.
    fn bar() -> usize;
}

struct A;

impl Foo for A {
    fn bar() -> usize { // Bad implementation. The verification error should be reported here.
        0
    }
}

struct B;

impl Foo for B {
    fn bar() -> usize { // Correct implementation
        100
    }
}

fn main(){}

@Aurel300
Copy link
Member

The failing implementation span is now added as a "note" to the error:

error: [Prusti: verification error] postcondition might not hold.
  --> example.rs:4:15
   |
4  |     #[ensures(result > 10)] // Failing postcondition. The verification error is currently reported here.
   |               ^^^^^^^^^^^
   |
note: the error originates here
  --> example.rs:11:5
   |
11 | /     fn bar() -> usize { // Bad implementation. The verification error should be reported here.
12 | |         0
13 | |     }
   | |_____^

Do we want to improve this any further? I think reporting the failing postcondition (or conjunct) as the primary span makes sense.

@Aurel300 Aurel300 added the error-reporting Something needs to be fixed in the error reporting label Mar 29, 2022
zgrannan pushed a commit to zgrannan/prusti-dev that referenced this issue Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request error-reporting Something needs to be fixed in the error reporting
Projects
None yet
Development

No branches or pull requests

3 participants