S1144 Is confused by Debugger Display attribute

Rule S1144: Unused private types or members should be removed tries to detect which private members can be removed as they are not called. If we look the following example:

public class Compliant
{
	public int Value(int value) => new Durs(value)[3];

	[DebuggerDisplay("{this[0]}, {this[1]}, {this[2]}, {this[3]}, {this[4]}")]
	readonly record struct Durs(int Value)
	{
		public int this[int pos] => (Value >> (pos << 2)) & 7; // FP: Called by both Value as DebuggerDisplay.
	}
}

We see that it reports that the index property is not used. If we remove the [DebuggerDisplay] declaration the warning disappears.

In this example, the debugger display even references the index property, but the content of the [DebuggerDisplay] does not seems to make a difference.

Reported by SonarAnalyzer.CSharp v10.16.1.129956.

Hey @Corniel,

Thanks for the report.
Can confirm that this is an FP.
Nice find, this is a weird one!

I’ve added a ticket to our backlog and a repro to the codebase.

1 Like

Hi @Corniel ,
Just letting you know we just released version 10.18 of our analyzers which fixes this issue.

2 Likes