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

Ensure that we always run all diagnostic suppressors for single file analysis #68270

Merged
merged 1 commit into from
May 26, 2023

Conversation

mavasani
Copy link
Contributor

@mavasani mavasani commented May 19, 2023

Fixes AB#1819603

If CompilationWithAnalyzers host passes in suppressors into CompilationWithAnalyzers constructor, but does not pass these suppressors into the public APIs on it that compute and return diagnostics for a given subset of analyzers, then the driver was skipping executing these suppressors on the reported diagnostics.

This change ensures that the AnalyzerDriver is always passed in all the DiagnosticSuppressors to execute, regardless of whether or not they are part of the input set of analyzers passed into the public APIs on CompilationWithAnalyzers.

Verified that the added unit test fails before this change.

…ysis

Fixes [AB#1819603](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1819603)
If CompilationWithAnalyzers host passes in suppressors into CompilationWithAnalyzers constructor, but does not pass these suppressors into the public APIs on it that compute and return diagnostics for a given subset of analyzers, then the driver skips executing these suppressors on the reported diagnostics.
This change ensures that the AnalyzerDriver is always passed in all the DiagnosticSuppressors to execute, regardless of whether or not they are part of the input set of analyzers passed into the public APIs on CompilationWithAnalyzers.

Verified that the added unit test fails before this change.
@mavasani mavasani requested a review from a team as a code owner May 19, 2023 05:46
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label May 19, 2023
Comment on lines +363 to +370
var analyzers = analysisScope.Analyzers;
if (!suppressors.IsEmpty)
{
// Always provide all the diagnostic suppressors to the driver.
// We also need to ensure we are not passing any duplicate suppressor instances.
var suppressorsInAnalysisScope = analysisScope.Analyzers.OfType<DiagnosticSuppressor>().ToImmutableHashSet();
analyzers = analyzers.AddRange(suppressors.Where(suppressor => !suppressorsInAnalysisScope.Contains(suppressor)));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core fix

@mavasani
Copy link
Contributor Author

@dotnet/roslyn-compiler for another review - trivial fix

@RikkiGibson RikkiGibson self-assigned this May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants