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 couple of analyzer bugs #967

Merged
merged 3 commits into from
May 9, 2016
Merged

Conversation

mavasani
Copy link
Contributor

@mavasani mavasani commented May 9, 2016

  1. Fix DoNotDecreaseInheritedMemberVisibilityAnalyzer to match few more cases with binary FxCop
    Fixes CA2222 (DoNotDecreaseInheritedMemberVisibility) fires on members with resultant accessiblity private/internal #940
  2. Fix TypeNamesShouldNotMatchNamespacesAnalyzer to not report analyze/report diagnostics on generated code.
    Fixes TypeNamesShouldNotMatchNamespaces (CA1724) reports on WinForms designer-generated code #949
    Seems like invoking analysisContext.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze), which should suppress all diagnostics on generated code, still allows the analyzer to report compilation end diagnostics on generated code. I'll file a separate bug on roslyn repo to fix the driver.

…eport diagnostics on generated code.

Fixes dotnet#949

Seems like invoking analysisContext.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze), which should suppress all diagnostics on generated code, still allows the analyzer to report compilation end diagnostics on generated code. I'll file a separate bug on roslyn repo to fix the driver.
@mavasani
Copy link
Contributor Author

mavasani commented May 9, 2016

Tagging @dotnet/roslyn-analysis for review

@srivatsn
Copy link
Contributor

srivatsn commented May 9, 2016

👍

@bkoelman
Copy link
Contributor

@mavasani Did you already file a separate bug on roslyn repo to fix the driver?

I have looked around in the source of AnalyzerDriver / AnalyzerExecutor and believe there is no easy way to get this working.

SymbolAnalysisContext.ReportDiagnostic() does not receive the symbol it applies to. But it is always executed as a result of analyzing a known symbol (the one in SymbolAnalysisContext object). That known symbol is then checked for whether it comes from generated code, not the actual symbol on which a diagnostic is reported.

CompilationAnalysisContext.ReportDiagnostic() also does not receive the symbol it applies to, only the (first?) location (which is optional). As it may report anything from the compilation, it's not clear which source symbol/node/operation/... should be checked for whether it comes from generated code.

So I don't see an obvious way for the driver/executor to determine whether a symbol, syntax node, tree or operation comes from generated code in the Compilation End analysis.

@mavasani
Copy link
Contributor Author

@bkoelman I'll file it now. Note that we do the generated code filtering for reported diagnostics based on its primary location, not based on what context it was reported. See this method: http://source.roslyn.io/#Microsoft.CodeAnalysis/DiagnosticAnalyzer/AnalyzerDriver.cs,303.

We just need to fix this method to add this if check to do this filtering for compilation diagnostics, we seem to be doing it only for non-compilation diagnostics.

@mavasani
Copy link
Contributor Author

Opened dotnet/roslyn#11217

@bkoelman
Copy link
Contributor

@mavasani Yes you are correct. I see now how I got on the wrong track by looking at isGeneratedCode parameter. The primary location is actually used for source.

@mavasani mavasani deleted the FixAnalyzerBugs branch May 11, 2016 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants