Skip to content

DiagnosticCatalog silently hands out duplicate diagnostic IDs when a number is reused #20

Description

@matt-edmondson

What's wrong

DiagnosticCatalog.Add (SourceGeneratorToolkit/DiagnosticCatalog.cs:~56-68) formats {prefix}{number:000} without checking whether that number is already in use.

Reproduction (ran)

var catalog = new DiagnosticCatalog("X", "c");
catalog.Warning(1, "a", "a");
catalog.Error(1, "b", "b");

Both descriptors get the ID X001, with different titles, severities and messages, and both appear in Descriptors.

Why it matters

The catalog exists so that IDs can't drift or collide. With duplicates:

  • a .editorconfig severity override or #pragma suppression meant for one diagnostic silently applies to the other;
  • the docs and the analyzer release tracking see two different rules under one ID;
  • a test that walks Descriptors doesn't flag it.

Suggested fix / acceptance criteria

  • Track the numbers already used (a HashSet<int>) and throw ArgumentException from Add when a number is reused.
  • Add a test: registering the same number twice throws.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions