Skip to content

Unhelpful error message about reads clause #5262

Closed

Description

@MikaelMayer

Dafny version

latest-nightly

Code to produce this issue

trait Entries<T> {
  var entries: array<T>
  method Copy() returns (x: array<T>)
    ensures fresh(x) && x[..] == entries[..]
  {
    x := new T[entries.Length](
        i requires 0 <= i < entries.Length
        reads entries
        //    ^^^^^^^ Insufficient reads clause to read field
        => entries[i]);
  }
}

Command to run and resulting output

Paste in VSCode and see the error message.

What happened?

I did not get it why it could not read the array "entries" since it's in a method.
It turns out, "entries" is a shortcut for "this.entries", which means that this expression requires "reads this".
I think I would have immediately spotted it if, instead of the error message:

Insufficient reads clause to read field

I would have had the following error message, at least because "this" is implicit.

Insufficient reads clause to read field 'entries', perhaps try adding reads 'this' in the enclosing scope

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

Windows

Activity

  1. added
    kind: bug
    part: documentation
    kind: enhancement
    and removed
    kind: bug
    on Mar 27, 2024
  2. self-assigned this
    on Mar 28, 2024
  3. added a commit that references this issue on Mar 29, 2024
    4a3aace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind: enhancementpart: documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions