Skip to content

Constructing a HashSet<ISymbol> with SymbolEqualityComparer should not generate any warnings #4568

@Leemyy

Description

@Leemyy

Analyzer

Diagnostic ID: RS1024: Compare symbols correctly

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.Analyzers

Version: 3.3.2 (Latest)

Describe the bug

When constructing a HashSet<ISymbol> or a Dictionary<ISymbol, _> with the constructor override accepting an IEqualityComparer, passing in either SymbolEqualityComparer.Default or SymbolEqualityComparer.IncludeNullability still results is a warning.

Steps To Reproduce

  1. Create an new source generator project
  2. Within the Execute metod of the generator, write the line:
    HashSet<ISymbol> childTypes = new(SymbolEqualityComparer.Default);
  3. A warning will get reported on the constructor call

See here for an example of a (non-minimal) repro.

Expected behavior

No warning should be reported.

Actual behavior

A warning about improper Symbol comparison is reported.

Additional context

  • The warning gets reported both for HashSet<T> and Dictionary<K, V>
  • Using a qualified constructor insead of a target-typed constuctor makes no difference
  • The warning gets reported whenever the generic parameter is/derives from ISymbol

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions