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

Imprecise error message with partial functions #5872

Open
txiang61 opened this issue Oct 29, 2024 · 0 comments
Open

Imprecise error message with partial functions #5872

txiang61 opened this issue Oct 29, 2024 · 0 comments
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

Comments

@txiang61
Copy link

Dafny version

4.8.1

Code to produce this issue

function Map<T, U>(s: seq<T>, f: T ~> U): (res: seq<U>)
  reads set x, y | x in s && y in f.reads(x) :: y
  requires forall x: T :: x in s ==> f.requires(x)
  ensures |res| == |s|
  ensures forall i: nat :: i < |s| ==> res[i] == f(s[i])
  decreases |s|
{
  if s == [] then
    []
  else
    [f(s[0])] + Map(s[1..], f)
}

predicate R<T>(x: T)
predicate P<U>(x: U)

function goo<T, U>(x: T): (r: U)
  requires R(x)
  ensures P(r)

function foo<T, U>(x: seq<T>): (res: seq<U>)
  //   requires forall a <- x :: R(a)
  ensures forall r <- res :: P(r)
{
  Map(x, a requires R(a) => goo(a))
}

Command to run and resulting output

(22,9): Error: a postcondition could not be proved on this return path
   |
22 | function foo<T, U>(x: seq<T>): (res: seq<U>)
   |          ^^^

(24,10): Related location: this is the postcondition that could not be proved
   |
24 |   ensures forall r <- res :: P(r)
   |           ^^^^^^^^^^^^^^^^^^^^^^^

(26,2): Error: function precondition could not be proved
   |
26 |   Map(x, a requires R(a) => goo(a))
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(3,11): Related location: this proposition could not be proved
  |
3 |   requires forall x: T :: x in s ==> f.requires(x)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What happened?

The error message is complaining about the failure to satisfy the post-condition as well. The pre-condition should have turned into an assume for the post-condition to be proven. I also encountered a case where the error message only returned one error complaining about the post-condition and not the pre-condition, which caused some confusion.

What type of operating system are you experiencing the problem on?

Mac

@txiang61 txiang61 added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label
Projects
None yet
Development

No branches or pull requests

1 participant