Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa99269

Browse files
calumgranthvitved
authored andcommitted
C#: Fix merge conflicts. Unfortunately, the type of symbolEntityCache needed to be the same as objectEntityCache to fix nullability warnings.
1 parent 0cfe424 commit aa99269

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

csharp/extractor/Semmle.Extraction/Context.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public Entity CreateEntityFromSymbol<Type, Entity>(ICachedEntityFactory<Type, En
7575
where Entity : ICachedEntity
7676
where Type : ISymbol
7777
{
78-
return init == null ? CreateEntity2(factory, init) : CreateNonNullEntity(factory, init);
78+
return init == null ? CreateEntity2(factory, init) : CreateNonNullEntity(factory, init, symbolEntityCache);
7979
}
8080

8181
// A recursion guard against writing to the trap file whilst writing an id to the trap file.
@@ -161,11 +161,11 @@ private void CheckEntityHasUniqueLabel(string id, ICachedEntity entity)
161161

162162
public Entity CreateNonNullEntity<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init)
163163
where Entity : ICachedEntity
164+
where Type : notnull
164165
=> CreateNonNullEntity(factory, init, objectEntityCache);
165166

166-
private Entity CreateNonNullEntity<Type, Src, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init, IDictionary<Src, ICachedEntity> dictionary)
167+
private Entity CreateNonNullEntity<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init, IDictionary<object, ICachedEntity> dictionary)
167168
where Entity : ICachedEntity
168-
where Type : Src
169169
{
170170
if (init is null) throw new ArgumentException("Unexpected null value", nameof(init));
171171

@@ -233,8 +233,18 @@ public void AddFreshLabel(IEntity entity)
233233
readonly Dictionary<string, ICachedEntity> idLabelCache = new Dictionary<string, ICachedEntity>();
234234
#endif
235235

236+
// Adaptor to convert IEqualityComparer<ISymbol> to IEqualityComparer<object>
237+
class SymbolComparer : IEqualityComparer<object>
238+
{
239+
IEqualityComparer<ISymbol> comparer = SymbolEqualityComparer.IncludeNullability;
240+
241+
bool IEqualityComparer<object>.Equals(object? x, object? y) => comparer.Equals(x as ISymbol, y as ISymbol);
242+
243+
int IEqualityComparer<object>.GetHashCode(object obj) => comparer.GetHashCode((ISymbol)obj);
244+
}
245+
236246
readonly IDictionary<object, ICachedEntity> objectEntityCache = new Dictionary<object, ICachedEntity>();
237-
readonly IDictionary<ISymbol, ICachedEntity> symbolEntityCache = new Dictionary<ISymbol, ICachedEntity>(10000, SymbolEqualityComparer.IncludeNullability);
247+
readonly IDictionary<object, ICachedEntity> symbolEntityCache = new Dictionary<object, ICachedEntity>(10000, new SymbolComparer());
238248
readonly Dictionary<ICachedEntity, Label> entityLabelCache = new Dictionary<ICachedEntity, Label>();
239249
readonly HashSet<Label> extractedGenerics = new HashSet<Label>();
240250

0 commit comments

Comments
 (0)