C#: Fix merge conflicts. Unfortunately, the type of symbolEntityCache needed to be the same as objectEntityCache to fix nullability warnings.

This commit is contained in:
Calum Grant
2020-05-18 21:03:48 +01:00
committed by Tom Hvitved
parent 0cfe424fc2
commit aa99269015

View File

@@ -75,7 +75,7 @@ namespace Semmle.Extraction
where Entity : ICachedEntity
where Type : ISymbol
{
return init == null ? CreateEntity2(factory, init) : CreateNonNullEntity(factory, init);
return init == null ? CreateEntity2(factory, init) : CreateNonNullEntity(factory, init, symbolEntityCache);
}
// A recursion guard against writing to the trap file whilst writing an id to the trap file.
@@ -161,11 +161,11 @@ namespace Semmle.Extraction
public Entity CreateNonNullEntity<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init)
where Entity : ICachedEntity
where Type : notnull
=> CreateNonNullEntity(factory, init, objectEntityCache);
private Entity CreateNonNullEntity<Type, Src, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init, IDictionary<Src, ICachedEntity> dictionary)
private Entity CreateNonNullEntity<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init, IDictionary<object, ICachedEntity> dictionary)
where Entity : ICachedEntity
where Type : Src
{
if (init is null) throw new ArgumentException("Unexpected null value", nameof(init));
@@ -233,8 +233,18 @@ namespace Semmle.Extraction
readonly Dictionary<string, ICachedEntity> idLabelCache = new Dictionary<string, ICachedEntity>();
#endif
// Adaptor to convert IEqualityComparer<ISymbol> to IEqualityComparer<object>
class SymbolComparer : IEqualityComparer<object>
{
IEqualityComparer<ISymbol> comparer = SymbolEqualityComparer.IncludeNullability;
bool IEqualityComparer<object>.Equals(object? x, object? y) => comparer.Equals(x as ISymbol, y as ISymbol);
int IEqualityComparer<object>.GetHashCode(object obj) => comparer.GetHashCode((ISymbol)obj);
}
readonly IDictionary<object, ICachedEntity> objectEntityCache = new Dictionary<object, ICachedEntity>();
readonly IDictionary<ISymbol, ICachedEntity> symbolEntityCache = new Dictionary<ISymbol, ICachedEntity>(10000, SymbolEqualityComparer.IncludeNullability);
readonly IDictionary<object, ICachedEntity> symbolEntityCache = new Dictionary<object, ICachedEntity>(10000, new SymbolComparer());
readonly Dictionary<ICachedEntity, Label> entityLabelCache = new Dictionary<ICachedEntity, Label>();
readonly HashSet<Label> extractedGenerics = new HashSet<Label>();