Skip to content

Commit 0ceb2f3

Browse files
authored
Merge pull request #20442 from aschackmull/csharp/default-tostring-enum
C#: Exclude enum types as they don't inherit the default toString.
2 parents 57e15b9 + 107d142 commit 0ceb2f3

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

csharp/ql/src/Useless code/DefaultToStringQuery.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private predicate alwaysInvokesToString(ParameterRead pr) {
4747
*/
4848
predicate alwaysDefaultToString(ValueOrRefType t) {
4949
not t instanceof TupleType and
50+
not t instanceof Enum and
5051
exists(ToStringMethod m | t.hasMethod(m) |
5152
m.getDeclaringType() instanceof SystemObjectClass or
5253
m.getDeclaringType() instanceof SystemValueTypeClass
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The query `cs/call-to-object-tostring` has been improved to remove false positives for enum types.

0 commit comments

Comments
 (0)