diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs index 1080421986cd..c2f2bfa321ca 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/Type.cs @@ -93,7 +93,7 @@ protected void PopulateType(TextWriter trapFile) // Visit base types var baseTypes = new List(); - if (symbol.BaseType != null) + if (symbol.BaseType != null && symbol.BaseType.SpecialType != SpecialType.System_Object) { Type baseKey = Create(Context, symbol.BaseType); trapFile.extend(this, baseKey.TypeRef); @@ -101,11 +101,6 @@ protected void PopulateType(TextWriter trapFile) baseTypes.Add(baseKey); } - if (symbol.TypeKind == TypeKind.Interface) - { - trapFile.extend(this, Create(Context, Context.Compilation.ObjectType)); - } - if (!(base.symbol is IArrayTypeSymbol)) { foreach (var t in base.symbol.Interfaces.Select(i=>Create(Context, i))) diff --git a/csharp/ql/src/semmle/code/csharp/Type.qll b/csharp/ql/src/semmle/code/csharp/Type.qll index 0536098cf4a7..af62a994ac38 100644 --- a/csharp/ql/src/semmle/code/csharp/Type.qll +++ b/csharp/ql/src/semmle/code/csharp/Type.qll @@ -111,7 +111,13 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_ } /** Gets the immediate base class of this class, if any. */ - Class getBaseClass() { extend(this, getTypeRef(result)) } + Class getBaseClass() { + extend(this, getTypeRef(result)) + or + not extend(this, _) and + not this instanceof ObjectType and + result instanceof ObjectType + } /** Gets an immediate base interface of this type, if any. */ Interface getABaseInterface() { implement(this, getTypeRef(result)) }