Skip to content

Commit

Permalink
If the last generator is removed that was generating, correctly update
Browse files Browse the repository at this point in the history
If the last generator was removed, and it was generating trees, we would
have potentially left that tree in the Compilation that was returned.
I believe this would have been a transient issue -- any later change
to the project would have created a new CompilationTracker with an
InProgress state; the code that processes an InProgress state into
the final state would have correctly seen we no longer had a generator
and would have dropped the old compilation at that point.
  • Loading branch information
jasonmalinowski committed Oct 27, 2022
1 parent 1079153 commit 68391a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,12 @@ private async Task<CompilationInfo> FinalizeCompilationAsync(
{
using var generatedDocumentsBuilder = new TemporaryArray<SourceGeneratedDocumentState>();

if (ProjectState.SourceGenerators.Any())
if (!ProjectState.SourceGenerators.Any())
{
// We don't have any generators, so if we have a compilation from a previous run with generated files, we definitely can't use it anymore
compilationWithStaleGeneratedTrees = null;
}
else // we have a generator
{
// If we don't already have a generator driver, we'll have to create one from scratch
if (generatorInfo.Driver == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public async Task WithReferencesMethodCorrectlyUpdatesWithEqualReferences()
project = project.WithAnalyzerReferences(new[] { analyzerReference2 });

Assert.Single((await project.GetRequiredCompilationAsync(CancellationToken.None)).SyntaxTrees);

// Now remove and confirm that we don't have any files
project = project.WithAnalyzerReferences(SpecializedCollections.EmptyEnumerable<AnalyzerReference>());

Assert.Empty((await project.GetRequiredCompilationAsync(CancellationToken.None)).SyntaxTrees);
}

private class TestGeneratorReferenceWithFilePathEquality : TestGeneratorReference, IEquatable<AnalyzerReference>
Expand Down

0 comments on commit 68391a3

Please sign in to comment.