Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,14 @@ protected void PopulateType(TextWriter trapFile)

// Visit base types
var baseTypes = new List<Type>();
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);
if (symbol.TypeKind != TypeKind.Struct)
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)))
Expand Down
8 changes: 7 additions & 1 deletion csharp/ql/src/semmle/code/csharp/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this result instanceof ObjectType and not result = ObjectType?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter is not valid QL syntax, as the right-hand-side is a QL class and not an expression. result = any(ObjectType ot) would work, but instanceof is better IMO. Note that the extractor will guarantee that there is indeed only one element inside ObjectType.

}

/** Gets an immediate base interface of this type, if any. */
Interface getABaseInterface() { implement(this, getTypeRef(result)) }
Expand Down