Skip to content

Commit

Permalink
Merge pull request #6959 from mavasani/FixIssue6852
Browse files Browse the repository at this point in the history
Handle reference to non-source symbols in UseConcreteTypeAnalyzer
  • Loading branch information
mavasani authored Sep 21, 2023
2 parents 1066c7c + a6c29fa commit 4aefee9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public override void Initialize(AnalysisContext context)
context.RegisterCompilationStartAction(context =>
{
var voidType = context.Compilation.GetSpecialType(SpecialType.System_Void);
var publicOrInternalColl = Collector.GetInstance(voidType, symbol => context.Options.MatchesConfiguredVisibility(UseConcreteTypeForMethodReturn, symbol, context.Compilation, SymbolVisibilityGroup.Private));
var publicOrInternalColl = Collector.GetInstance(voidType, symbol => symbol.IsInSource() && context.Options.MatchesConfiguredVisibility(UseConcreteTypeForMethodReturn, symbol, context.Compilation, SymbolVisibilityGroup.Private));
context.RegisterSymbolStartAction(context =>
{
Expand All @@ -134,7 +134,7 @@ public override void Initialize(AnalysisContext context)
return;
}
var coll = Collector.GetInstance(voidType, symbol => context.Options.MatchesConfiguredVisibility(UseConcreteTypeForMethodReturn, symbol, context.Compilation, SymbolVisibilityGroup.Private));
var coll = Collector.GetInstance(voidType, symbol => symbol.IsInSource() && context.Options.MatchesConfiguredVisibility(UseConcreteTypeForMethodReturn, symbol, context.Compilation, SymbolVisibilityGroup.Private));
// we accumulate a bunch of info in the collector object
context.RegisterOperationAction(context => coll.HandleInvocation((IInvocationOperation)context.Operation), OperationKind.Invocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,24 @@ public bool GetIFoo(out IFoo ifoo)
await TestCSAsync(Source);
}

[Fact, WorkItem(6852, "https://github.com/dotnet/roslyn-analyzers/issues/6852")]
public static async Task ShouldNotCrashForInvocationsIntoMetadata()
{
const string Source = @"
using System;
class C
{
private void M(ValueTuple<Action> vt)
{
vt.Item1();
}
}
";

await TestCSAsync(Source);
}

private static async Task TestCSAsync(string source, params DiagnosticResult[] diagnosticResults)
{
var test = new VerifyCS.Test
Expand Down

0 comments on commit 4aefee9

Please sign in to comment.