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

Fix least lemma IDE verification bug and add test #4607

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading