Merge pull request #20442 from aschackmull/csharp/default-tostring-enum

C#: Exclude enum types as they don't inherit the default toString.
This commit is contained in:
Anders Schack-Mulligen
2025-09-16 11:12:21 +02:00
committed by GitHub
2 changed files with 5 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ private predicate alwaysInvokesToString(ParameterRead pr) {
*/
predicate alwaysDefaultToString(ValueOrRefType t) {
not t instanceof TupleType and
not t instanceof Enum and
exists(ToStringMethod m | t.hasMethod(m) |
m.getDeclaringType() instanceof SystemObjectClass or
m.getDeclaringType() instanceof SystemValueTypeClass

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The query `cs/call-to-object-tostring` has been improved to remove false positives for enum types.