Closed
Description
Version Used: Compiler version: '4.14.0-1.25105.1 (842cb1bc)'. Language version: latest (13.0).
Steps to Reproduce:
- Create a new C# Console Application in VS 2022 v17.14.0 Preview 1 (it may also occur earlier, I didn't test)
- Update the code to the following:
int[] a = new int[5];
MyStruct m = new MyStruct(a);
m[0] = 1; // IDE0059: Unnecessary assignment of a value to 'm'
Console.WriteLine(a[0]);
struct MyStruct(int[] a)
{
private int[] array = a;
public int this[int index]
{
get => array[index];
set => array[index] = value;
}
}
- Observe that the line containing
m[0] = 1;
is flagged with ``
Diagnostic Id: IDE0059: Unnecessary assignment of a value to '...'
Expected Behavior:
The IDE warning should not trigger for method invocations or indexer usage, as these can trivially mutate indirect state. Such indirect side effects is the case in the example above where the contents of a
are observably changed via the m[0] = 1;