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

File IO functions missing contracts? #1272

Closed
mario-bucev opened this issue May 25, 2022 · 0 comments · Fixed by #1277
Closed

File IO functions missing contracts? #1272

mario-bucev opened this issue May 25, 2022 · 0 comments · Fixed by #1277

Comments

@mario-bucev
Copy link
Collaborator

mario-bucev commented May 25, 2022

Consider the following snippet:

import stainless._
import stainless.lang._
import stainless.io._

object IO {

  def read(fis: FileInputStream)(using State): Unit = {
    require(fis.isOpen)
    val a1 = fis.tryReadByte() // ok
    val a2 = fis.tryReadByte() // invalid
  }

  def write(fos: FileOutputStream): Unit = {
    // `fos.write` requires `fos.isOpen`, but we can get away without?
    fos.write(1)
    fos.write(2)
  }
}

It seems that tryReadByte should at least specifies in its postcondition that the file remains open.
As for fos.write, it seems that the requirement is for some reason ignored (edit: affected by #1274).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant