Skip to content

Commit

Permalink
Fix least lemma IDE verification bug and add test (#4607)
Browse files Browse the repository at this point in the history
### Changes
Allow least lemmas to be verified in the IDE

### Testing
Added XUnit test

<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>
  • Loading branch information
keyboardDrummer committed Oct 4, 2023
1 parent 8bef7fd commit ea90036
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Source/DafnyLanguageServer.Test/Synchronization/DiagnosticsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ namespace Microsoft.Dafny.LanguageServer.IntegrationTest.Synchronization {
public class DiagnosticsTest : ClientBasedLanguageServerTest {
private readonly string testFilesDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Synchronization/TestFiles");

[Fact]
public async Task LeastLemmaIsVerified() {
var source = @"
least lemma Foo()
ensures false
{}";
var document = await CreateOpenAndWaitForResolve(source);
var diagnostics = await GetLastDiagnostics(document);
Assert.NotEmpty(diagnostics);
}

[Fact(Skip = "Not implemented. Requires separating diagnostics from different sources")]
public async Task FixedParseErrorUpdatesBeforeResolution() {
var source = @"
Expand Down
19 changes: 15 additions & 4 deletions Source/DafnyLanguageServer/Workspace/CompilationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ public async Task<bool> VerifySymbol(FilePosition verifiableLocation, bool onlyP
cancellationSource.Token.ThrowIfCancellationRequested();

var compilation = await ResolvedCompilation;
var verifiable = compilation.Program.FindNode<ICanVerify>(verifiableLocation.Uri, verifiableLocation.Position.ToDafnyPosition());
if (verifiable == null) {
return false;
}

if (compilation.ResolutionDiagnostics.Values.SelectMany(x => x).Any(d =>
d.Level == ErrorLevel.Error &&
Expand All @@ -172,6 +168,21 @@ public async Task<bool> VerifySymbol(FilePosition verifiableLocation, bool onlyP
throw new TaskCanceledException();
}

var verifiable = compilation.Program.FindNode(verifiableLocation.Uri, verifiableLocation.Position.ToDafnyPosition(),
node => {
if (node is not ICanVerify) {
return false;
}
// Sometimes traversing the AST can return different versions of a single source AST node,
// for example in the case of a LeastLemma, which is later also represented as a PrefixLemma.
// This check ensures that we consistently use the same version of an AST node.
return compilation.Verifiables!.Contains(node);
}) as ICanVerify;

if (verifiable == null) {
return false;
}

var containingModule = verifiable.ContainingModule;
if (!containingModule.ShouldVerify(compilation.Program.Compilation)) {
return false;
Expand Down
1 change: 1 addition & 0 deletions docs/dev/news/4607.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that prevented certain types of lemma to be verified in the IDE

0 comments on commit ea90036

Please sign in to comment.