Skip to content

Commit fb0cae8

Browse files
committed
C#: Fix some alerts, and fix a potential NullReferenceException.
1 parent b0dd3df commit fb0cae8

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

csharp/extractor/Semmle.Extraction.CIL/Entities/Method.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ public MemberReferenceMethod(GenericContext gc, MemberReferenceHandle handle) :
402402

403403
declType = parentMethod == null ? parent as Type : parentMethod.DeclaringType;
404404

405+
if (declType is null)
406+
throw new InternalError("Parent context of method is not a type");
407+
405408
ShortId = MakeMethodId(declType, nameLabel);
406409

407410
var typeSourceDeclaration = declType.SourceDeclaration;

csharp/extractor/Semmle.Extraction.CIL/Entities/Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ class GenericMethodParameter : ITypeSignature
11211121
static readonly Id excl = Id.Create("M!");
11221122
public Id MakeId(GenericContext outerGc)
11231123
{
1124-
if (innerGc != outerGc && innerGc is Method method)
1124+
if (!ReferenceEquals(innerGc, outerGc) && innerGc is Method method)
11251125
return open + method.Label.Value + close + excl + index;
11261126
return excl + index;
11271127
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public static void ExtractModifiers(Context cx, IEntity key, ISymbol symbol)
134134
if (symbol.Kind == SymbolKind.NamedType)
135135
{
136136
INamedTypeSymbol nt = symbol as INamedTypeSymbol;
137+
if (nt is null)
138+
throw new InternalError(symbol, "Symbol kind is inconsistent with its type");
139+
137140
if (nt.TypeKind == TypeKind.Struct)
138141
{
139142
// Sadly, these properties are internal so cannot be accessed directly.

csharp/extractor/Semmle.Extraction/Context.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private void CheckEntityHasUniqueLabel(IId id, ICachedEntity entity)
9393
{
9494
if (idLabelCache.TryGetValue(id, out var originalEntity))
9595
{
96-
Extractor.Message(new Message { message = "Label collision for " + id.ToString(), severity = Severity.Warning });
96+
Extractor.Message(new Message { message = "Label collision for " + id, severity = Severity.Warning });
9797
}
9898
else
9999
{

csharp/extractor/Semmle.Extraction/Symbol.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected void WithDuplicationGuard(System.Action a, IEntity location)
5757
public override bool Equals(object obj)
5858
{
5959
var other = obj as CachedEntity<Initializer>;
60-
return obj != null && obj.GetType() == GetType() && Equals(other.symbol, symbol);
60+
return other != null && other.GetType() == GetType() && Equals(other.symbol, symbol);
6161
}
6262

6363
public abstract TrapStackBehaviour TrapStackBehaviour { get; }

0 commit comments

Comments
 (0)