Skip to content

Commit

Permalink
fix: "Failing precondition" on tooltip instead of "return path" (#2654)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelMayer authored Aug 31, 2022
1 parent 17fbc2d commit d6b6927
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- fix: Fixed a crash when parsing `newtype` in the parser (https://github.com/dafny-lang/dafny/pull/2649)
- fix: Added missing error reporting position on string prefix check (https://github.com/dafny-lang/dafny/pull/2652)
- fix: Check all compiled expressions to be compilable (https://github.com/dafny-lang/dafny/pull/2641)
- fix: Better messages on hovering failing postconditions in IDE (https://github.com/dafny-lang/dafny/pull/2654)
- fix: Better error reporting on counter-examples if an option is not provided (https://github.com/dafny-lang/dafny/pull/2650)

# 3.8.0
Expand Down
27 changes: 20 additions & 7 deletions Source/DafnyLanguageServer.Test/Lookup/HoverVerificationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Microsoft.Dafny.LanguageServer.IntegrationTest.Lookup {
[TestClass]
public class HoverVerificationTest : DafnyLanguageServerTestBase {
private const int MaxTestExecutionTimeMs = 10000;
private const int MaxTestExecutionTimeMs = 30000;

private ILanguageClient client;
private TestNotificationReceiver<CompilationStatusParams> notificationReceiver;
Expand Down Expand Up @@ -96,7 +96,7 @@ This is the only assertion in [batch](???) #2 of 3 in method f
await AssertHoverMatches(documentItem, (2, 12),
@"<span style='color:green'>**Success:**</span> assertion always holds
This is the only assertion in [batch](???) #3 of 3 in method f
[Batch](???) #3 resource usage: ??? RU "
[Batch](???) #3 resource usage: ??? RU"
);
await AssertHoverMatches(documentItem, (0, 36),
@"**Verification performance metrics for method f**:
Expand Down Expand Up @@ -129,7 +129,7 @@ await AssertHoverMatches(documentItem, (2, 12),
await AssertHoverMatches(documentItem, (3, 26),
@"[**Error:**](???) assertion might not hold
This is assertion #1 of 2 in [batch](???) #2 of 2 in function f
[Batch](???) #2 resource usage: ??? RU "
[Batch](???) #2 resource usage: ??? RU"
);
await AssertHoverMatches(documentItem, (0, 36),
@"**Verification performance metrics for function f**:
Expand All @@ -147,7 +147,6 @@ public async Task MeaningfulMessageWhenMethodWithoutAssert() {
method f(x: int) {
print x;
}", "testfile.dfy");
await Task.Delay(100); // Just time for the diagnostics to be updated
await AssertHoverMatches(documentItem, (0, 7),
@"**Verification performance metrics for method f**:
Expand All @@ -158,13 +157,29 @@ await AssertHoverMatches(documentItem, (0, 10),
}


[TestMethod, Timeout(MaxTestExecutionTimeMs)]
public async Task MeaningfulMessageForFailingPreconditions() {
var documentItem = await GetDocumentItem(@"
method Test1() {
Test2(0); // Hover #1
}
method Test2(i: int)
requires i > 0 {
}", "testfile.dfy");
await AssertHoverMatches(documentItem, (1, 10),
@"???
Failing precondition:???"
);
}

[TestMethod, Timeout(MaxTestExecutionTimeMs)]
public async Task MeaningfulMessageWhenMethodWithOneAssert() {
var documentItem = await GetDocumentItem(@"
method f(x: int) {
assert false;
}", "testfile1.dfy");
await Task.Delay(100); // Just time for the diagnostics to be updated
await AssertHoverMatches(documentItem, (0, 7),
@"**Verification performance metrics for method f**:
Expand All @@ -181,7 +196,6 @@ method f(x: int) {
assert false;
assert false;
}", "testfile2.dfy");
await Task.Delay(100); // Just time for the diagnostics to be updated
await AssertHoverMatches(documentItem, (0, 7),
@"**Verification performance metrics for method f**:
Expand All @@ -208,7 +222,6 @@ requires p > 0 && q > 0
}
assert {:split_here} true;
} ", "testfileSlow.dfy");
await Task.Delay(100); // Just time for the diagnostics to be updated
await AssertHoverMatches(documentItem, (0, 22),
@"**Verification performance metrics for method SquareRoot2NotRational**:
Expand Down
10 changes: 8 additions & 2 deletions Source/DafnyLanguageServer/Handlers/DafnyHoverHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ private string GetAssertionInformation(Position position, AssertionVerificationT


var currentlyHoveringPostcondition =
!(assertionNode.GetCounterExample() is ReturnCounterexample returnCounterexample2 &&
returnCounterexample2.FailingReturn.tok.GetLspRange().Contains(position));
assertionNode.GetCounterExample() is ReturnCounterexample returnCounterexample2 &&
!returnCounterexample2.FailingReturn.tok.GetLspRange().Contains(position);

var obsolescence = assertionNode.StatusCurrent switch {
CurrentStatus.Current => "",
Expand Down Expand Up @@ -251,6 +251,12 @@ string GetDescription(Boogie.ProofObligationDescription? description) {
: "");
}

if (assertionNode.GetCounterExample() is CallCounterexample) {
information += " \n" + (assertionNode.SecondaryPosition != null
? $"Failing precondition: {Path.GetFileName(assertionNode.Filename)}({assertionNode.SecondaryPosition.Line + 1}, {assertionNode.SecondaryPosition.Character + 1})"
: "");
}

return information;
}

Expand Down

0 comments on commit d6b6927

Please sign in to comment.