diff --git a/src/Compilers/Core/Portable/Compilation/Compilation.cs b/src/Compilers/Core/Portable/Compilation/Compilation.cs index 98a6a4ba981c1..c8eb1c9461bb4 100644 --- a/src/Compilers/Core/Portable/Compilation/Compilation.cs +++ b/src/Compilers/Core/Portable/Compilation/Compilation.cs @@ -1169,7 +1169,9 @@ public INamedTypeSymbol CreateNativeIntegerTypeSymbol(bool signed) { val = CommonGetTypeByMetadataName(fullyQualifiedMetadataName); var result = _getTypeCache.TryAdd(fullyQualifiedMetadataName, val); - Debug.Assert(result || (_getTypeCache.TryGetValue(fullyQualifiedMetadataName, out var addedType) && ReferenceEquals(addedType, val))); + Debug.Assert(result + || !_getTypeCache.TryGetValue(fullyQualifiedMetadataName, out var addedType) // Could fail if the type was already evicted from the cache + || ReferenceEquals(addedType, val)); } return val; } @@ -1196,8 +1198,8 @@ public ImmutableArray GetTypesByMetadataName(string fullyQuali val = getTypesByMetadataNameImpl(); var result = _getTypesCache.TryAdd(fullyQualifiedMetadataName, val); Debug.Assert(result - || (_getTypesCache.TryGetValue(fullyQualifiedMetadataName, out var addedArray) - && Enumerable.SequenceEqual(addedArray, val, ReferenceEqualityComparer.Instance))); + || !_getTypesCache.TryGetValue(fullyQualifiedMetadataName, out var addedArray) // Could fail if the type was already evicted from the cache + || Enumerable.SequenceEqual(addedArray, val, ReferenceEqualityComparer.Instance)); } return val;