Skip to content

Function methods only ever have one return path, which makes debugging harder #1799

@cpitclaudel

Description

@cpitclaudel

Consider these two equivalent programs:

function method fIncorrectInOneCase(x: int) : (y: int)
  ensures y > 0
{
  if (x < -3) then 5
  else if (x < 5) then -2
  else 4
}

method mIncorrectInOneCase(x: int) returns (y: int)
  ensures y > 0
{
  if (x < -3) { return 5; }
  else if (x < 5) { return -2; }
  else { return 4; }
}

Here's Dafny's output:

image

The error is correctly positioned in the method, but not in the function. This makes debugging function methods much less pleasant than methods.

Here's the textual output:

test.dfy(1,16): Error: A postcondition might not hold on this return path.
test.dfy(2,12): Related location: This is the postcondition that might not hold.
Execution trace:
    (0,0): anon0
    (0,0): anon9_Else
    (0,0): anon10_Else
    (0,0): anon11_Then
    (0,0): anon8
test.dfy(13,20): Error: A postcondition might not hold on this return path.
test.dfy(10,12): Related location: This is the postcondition that might not hold.
Execution trace:
    (0,0): anon0
    (0,0): anon5_Else
    (0,0): anon6_Then

Btw, what's up with line numbers in execution traces?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: error-reportingClarity of the error reportingkind: enhancementEnhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafnypriority: not yetWill reconsider working on this when we're looking for work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions