Skip to content

Commit

Permalink
Fix NRE in RS1024
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Dec 1, 2020
1 parent 820d99a commit 5cc39c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private static void HandleObjectCreation(in OperationAnalysisContext context, IN
collectionTypes.Contains(createdType.OriginalDefinition) &&
!createdType.TypeArguments.IsEmpty &&
IsSymbolType(createdType.TypeArguments[0], symbolType) &&
!objectCreation.Arguments.Any(arg => arg.Type.Equals(symbolEqualityComparerType)))
!objectCreation.Arguments.Any(arg => IsSymbolType(arg.Type, symbolEqualityComparerType)))
{
context.ReportDiagnostic(objectCreation.CreateDiagnostic(CollectionRule));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.VisualBasic.Syntax;
using Test.Utilities;
using Xunit;
Expand Down Expand Up @@ -858,6 +859,31 @@ public void M(IEnumerable<ISymbol> e, ISymbol symbol, INamedTypeSymbol type)
.Where(x => x.IsAsync)
.ToLookup(x => x.ContainingType, x => x, SymbolEqualityComparer.Default);
}
}",
SymbolEqualityComparerStubCSharp,
},
},
}.RunAsync();
}

[Fact, WorkItem(4470, "https://github.com/dotnet/roslyn-analyzers/issues/4470")]
public async Task RS1024_InvocationArgumentTypeIsNull()
{
await new VerifyCS.Test
{
TestState =
{
Sources =
{
@"
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
public class C
{
private readonly HashSet<ITypeSymbol> _types = [|new HashSet<ITypeSymbol>(SymbolEqualityComparer.Default)|];
}",
SymbolEqualityComparerStubCSharp,
},
Expand Down

0 comments on commit 5cc39c6

Please sign in to comment.