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

Insert explicit assertion broken #4401

Closed
MikaelMayer opened this issue Aug 8, 2023 · 0 comments · Fixed by #4416
Closed

Insert explicit assertion broken #4401

MikaelMayer opened this issue Aug 8, 2023 · 0 comments · Fixed by #4416
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: language server Support for LSP in Dafny (server part; client is in ide-vscode repo)

Comments

@MikaelMayer
Copy link
Member

MikaelMayer commented Aug 8, 2023

Dafny version

4.2.0

Code to produce this issue

predicate P(i: int)

method Test() {
  var x :| P(x);
}

Another error there:

module Test {
  class TheTest {
    predicate P(i: int)

    method Test() {
      var x :| P(x);
    }
  }
}

Command to run and resulting output

Click on the error, select quick fix, insert failing assertion.

What happened?

image
image
image
The inserted text is garbage and not at the right place

Even worse if the method is wrapped in a class / module.
image

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

Windows

What solutions to offer

ImplicitFailingAssertionCodeActionProvider.cs line 38: would take care of the second

  protected static List<INode>? FindInnermostNodeIntersecting(INode node, Range range) {
    if (node.StartToken.line > 0 && !node.RangeToken.ToLspRange().Intersects(range)) {
      return null;
    }

    foreach (var child in node.PreResolveChildren) {
      var result = FindInnermostNodeIntersecting(child, range);
      if (result != null) {
        result.Add(node);
        return result;
      }
    }

-   return new List<INode> { node };
+   return node.StartToken.line > 0 ? new List<INode> { node } : null;
  }
@MikaelMayer MikaelMayer added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Aug 8, 2023
@fabiomadge fabiomadge added the part: language server Support for LSP in Dafny (server part; client is in ide-vscode repo) label Aug 13, 2023
keyboardDrummer added a commit that referenced this issue Aug 15, 2023
Fixes #4401

Previously, implicit assertions were inserted at the wrong place in the
presence of modules, and implicit existential assertions were printed
with wrong variables. This PR fixes both.

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>

---------

Co-authored-by: Remy Willems <[email protected]>
keyboardDrummer added a commit to keyboardDrummer/dafny that referenced this issue Sep 15, 2023
Fixes dafny-lang#4401

Previously, implicit assertions were inserted at the wrong place in the
presence of modules, and implicit existential assertions were printed
with wrong variables. This PR fixes both.

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>

---------

Co-authored-by: Remy Willems <[email protected]>
keyboardDrummer added a commit that referenced this issue Sep 19, 2023
Fixes #4401

Previously, implicit assertions were inserted at the wrong place in the
presence of modules, and implicit existential assertions were printed
with wrong variables. This PR fixes both.

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>

---------

Co-authored-by: Remy Willems <[email protected]>
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 part: language server Support for LSP in Dafny (server part; client is in ide-vscode repo)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants