Allow declaring DiagnosticAnalyzerAttributes on abstract classes without causing initialization errors #56340
Labels
Area-Analyzers
Concept-API
This issue involves adding, removing, clarification, or modification of an API.
Feature Request
Milestone
Background and Motivation
DiagnosticAnalyzerAttribute
is inheritable by deriving classes, meaning that abstract classes can make use of it, however Roslyn will attempt to initialize new instances of abstract classes. This will result in AD0001 warnings cryptically indicating that an instance of an abstract class could not be created.Usage Examples
Roslyn will attempt to initialize an instance of
DerivedAnalyzer
and another ofAnotherAnalyzer
, but notBaseAnalyzer
, because it's abstract. Both instances of the analyzers will be considered to be analyzers for C#.Solutions
From what I've been looking at, it's this LINQ expression to blame for this. Maybe an additional check for whether the referened type is abstract would deal with this problem.
Risks
Code that would otherwise throw an exception and cause an AD0001 warning, will no longer do. It's a really sad day for badly written analyzers.
The text was updated successfully, but these errors were encountered: