C#: Improve empty collection check to not report on collections with property writes

This commit is contained in:
Tamas Vajk
2020-09-08 12:53:13 +02:00
committed by Tamás Vajk
parent 399da6837a
commit d60b7c7297
3 changed files with 19 additions and 3 deletions

View File

@@ -152,6 +152,21 @@ class Test
break;
}
}
void f9()
{
var l1 = new MyList(); // BAD
var x1 = l1[0];
var l2 = new MyList(); // GOOD
var x2 = l2[0];
l2.Prop = 42;
}
class MyList : List<int>
{
public int Prop { get { return 0; } set { Add(value); } }
}
}
// semmle-extractor-options: /r:System.Collections.dll

View File

@@ -8,4 +8,5 @@
| ReadOnlyContainer.cs:91:13:91:14 | v8 | The contents of this container are never initialized. |
| ReadOnlyContainer.cs:96:13:96:14 | v9 | The contents of this container are never initialized. |
| ReadOnlyContainer.cs:99:13:99:15 | v10 | The contents of this container are never initialized. |
| ReadOnlyContainer.cs:121:13:121:15 | v11 | The contents of this container are never initialized. |
| ReadOnlyContainer.cs:121:13:121:15 | v11 | The contents of this container are never initialized. |
| ReadOnlyContainer.cs:158:13:158:14 | l1 | The contents of this container are never initialized. |