C#: Exclude interfaces and abstract classes from cs/call-to-object-tostring

This commit is contained in:
calum
2019-01-11 15:53:32 +00:00
parent 83e2689645
commit 931b6b4ee5
2 changed files with 10 additions and 1 deletions

View File

@@ -54,7 +54,9 @@ predicate alwaysDefaultToString(ValueOrRefType t) {
not exists(RefType overriding |
overriding.getAMethod() instanceof ToStringMethod and
overriding.getABaseType+() = t
)
) and
not t.isAbstract() and
not t instanceof Interface
}
newtype TDefaultToStringType = TDefaultToStringType0(ValueOrRefType t) { alwaysDefaultToString(t) }

View File

@@ -29,6 +29,9 @@ class DefaultToString
var sb = new StringBuilder();
sb.Append(new char[] { 'a', 'b', 'c' }, 0, 3); // GOOD
IInterface f = null;
Console.WriteLine(f); // GOOD
}
class A
@@ -48,6 +51,10 @@ class DefaultToString
{
override public string ToString() { return "D"; }
}
interface IInterface
{
}
}
// semmle-extractor-options: /r:System.Runtime.Extensions.dll