Skip to content

Commit a85131b

Browse files
committed
C#: Better handling of (value) tuple types in cs/call-to-object-tostring.
1 parent 5eb305d commit a85131b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private predicate alwaysInvokesToString(ParameterRead pr) {
4646
* method from `System.Object` or `System.ValueType`.
4747
*/
4848
predicate alwaysDefaultToString(ValueOrRefType t) {
49+
not t instanceof TupleType and
4950
exists(ToStringMethod m | t.hasMethod(m) |
5051
m.getDeclaringType() instanceof SystemObjectClass or
5152
m.getDeclaringType() instanceof SystemValueTypeClass
@@ -55,6 +56,11 @@ predicate alwaysDefaultToString(ValueOrRefType t) {
5556
overriding.getABaseType+() = t
5657
) and
5758
((t.isAbstract() or t instanceof Interface) implies not t.isEffectivelyPublic())
59+
or
60+
exists(ValueOrRefType elem |
61+
elem = t.(TupleType).getElementType(_) and
62+
alwaysDefaultToString(elem)
63+
)
5864
}
5965

6066
class DefaultToStringType extends ValueOrRefType {

0 commit comments

Comments
 (0)