dafny icon indicating copy to clipboard operation
dafny copied to clipboard

function refinement broken

Open erniecohen opened this issue 10 months ago • 2 comments

Dafny version

4.5.0, 4.6.0, nightly

Code to produce this issue

abstract module A {
  function F(x: int): (r: int)
    ensures r > x
}

module B refines A {
  function F ... 
  // the result type of function 'F' (bool) differs from the result type of the corresponding function in the module it refines (int)
  // function 'F' is declared with a different number of parameter (0 instead of 1) than the corresponding function in the module it refines
  { x + 1 }
}

Command to run and resulting output

vscode

What happened?

The example above from the manual fails in the resolver. It worked through 4.4.0.

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

Mac

erniecohen avatar Apr 25 '24 20:04 erniecohen

The documentation seems to indicate this should work, although I'm not used to this syntax either:

image

We could check with @RustanLeino to see whether he intends to keep the semantics as the documentation currently defines it.

keyboardDrummer avatar Apr 26 '24 09:04 keyboardDrummer

A workaround is to skip the refinement notation, e.g.

module B refines A {
  function F(x: int): (r: int)
  { x + 1 }
}

Note that if the refined module defines a precondition, you cannot repeat this precondition in the refining module.

erniecohen avatar Apr 29 '24 10:04 erniecohen