dotnet / roslyn-analyzers

MIT License
1.6k stars 467 forks source link

RS1039 (GetDeclaredSymbol will always return null) has a number of false positives #7436

Open 333fred opened 1 month ago

333fred commented 1 month ago

Analyzer

Diagnostic ID: RS1039: GetDeclaredSymbol will always return null

Analyzer source

Version: Microsoft.CodeAnalysis.Analyzers 3.11.0

Describe the bug

There are a number of false positives in the analyzer. Some false positives it flags in roslyn:

https://github.com/dotnet/roslyn/blob/62af60c7637252896646f0e0df015d42bb584b7f/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelAPITests.cs#L1886 - error RS1039: A call to 'SemanticModel.GetDeclaredSymbol(StatementSyntax)' will always return 'null' https://github.com/dotnet/roslyn/blob/62af60c7637252896646f0e0df015d42bb584b7f/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs#L8313 - error RS1039: A call to 'SemanticModel.GetDeclaredSymbol(ModifiedIdentifierSyntax)' will always return 'null' https://github.com/dotnet/roslyn/blob/62af60c7637252896646f0e0df015d42bb584b7f/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DeclaringSyntaxNodeTests.cs#L141 - error RS1039: A call to 'SemanticModel.GetDeclaredSymbol(TNode)' will always return 'null' https://github.com/dotnet/roslyn/blob/62af60c7637252896646f0e0df015d42bb584b7f/src/Compilers/CSharp/Test/Emit3/Semantics/PatternMatchingTests_ListPatterns.cs#L4259 - error RS1039: A call to 'SemanticModel.GetDeclaredSymbol(VariableDesignationSyntax)' will always return 'null'

These are only a few of the false positives. A full list can be obtained by building dotnet/roslyn and turning RS1039 back on; I've turned it off for now due to the noise.