未验证 提交 606f9468 编写于 作者: M Manish Vasani 提交者: GitHub

Merge pull request #32752 from mavasani/Issue32702

Account for both parts of partial methods while computing dependent s…
......@@ -2913,5 +2913,69 @@ public void TestSymbolStartAnalyzer_NestedOperationAction_Inside_AllSymbolKinds(
Diagnostic("SymbolStartRuleId").WithArguments("e1", "Analyzer5").WithLocation(1, 1),
Diagnostic("SymbolStartRuleId").WithArguments("f1", "Analyzer6").WithLocation(1, 1));
}
[Fact, WorkItem(32702, "https://github.com/dotnet/roslyn/issues/32702")]
public void TestInvocationInPartialMethod()
{
string source1 = @"
static partial class B
{
static partial void PartialMethod();
}";
string source2 = @"
static partial class B
{
static partial void PartialMethod()
{
M();
}
private static void M() { }
}";
var compilation = CreateCompilationWithMscorlib45(new[] { source1, source2 });
compilation.VerifyDiagnostics();
var analyzers = new DiagnosticAnalyzer[] { new SymbolStartAnalyzer(topLevelAction: false, SymbolKind.NamedType, OperationKind.Invocation) };
var expected = new[] {
Diagnostic("OperationRuleId").WithArguments("B", "PartialMethod", "M()", "Analyzer1").WithLocation(1, 1),
Diagnostic("SymbolStartRuleId").WithArguments("B", "Analyzer1").WithLocation(1, 1)
};
compilation.VerifyAnalyzerDiagnostics(analyzers, expected: expected);
}
[Fact, WorkItem(32702, "https://github.com/dotnet/roslyn/issues/32702")]
public void TestFieldReferenceInPartialMethod()
{
string source1 = @"
static partial class B
{
static partial void PartialMethod();
}";
string source2 = @"
static partial class B
{
static partial void PartialMethod()
{
var x = _field;
}
private static int _field = 0;
}";
var compilation = CreateCompilationWithMscorlib45(new[] { source1, source2 });
compilation.VerifyDiagnostics();
var analyzers = new DiagnosticAnalyzer[] { new SymbolStartAnalyzer(topLevelAction: true, SymbolKind.NamedType, OperationKind.FieldReference) };
var expected = new[] {
Diagnostic("OperationRuleId").WithArguments("B", "PartialMethod", "_field", "Analyzer1").WithLocation(1, 1),
Diagnostic("SymbolStartTopLevelRuleId").WithArguments("B", "Analyzer1").WithLocation(1, 1)
};
compilation.VerifyAnalyzerDiagnostics(analyzers, expected: expected);
}
}
}
......@@ -173,6 +173,13 @@ void processMembers(IEnumerable<ISymbol> members)
{
memberSet = memberSet ?? new HashSet<ISymbol>();
memberSet.Add(member);
// Ensure that we include symbols for both parts of partial methods.
if (member is IMethodSymbol method &&
!(method.PartialImplementationPart is null))
{
memberSet.Add(method.PartialImplementationPart);
}
}
if (member.Kind != symbol.Kind &&
......
......@@ -2257,6 +2257,35 @@ partial class MyClass
static class MyClass3
{
}
</Document>
</Project>
</Workspace>");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedMembers)]
[WorkItem(32702, "https://github.com/dotnet/roslyn/issues/32702")]
public async Task UsedExtensionMethod_ReferencedFromPartialMethod()
{
await TestDiagnosticMissingAsync(
@"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document>
static partial class B
{
static partial void PartialMethod();
}
</Document>
<Document>
static partial class B
{
static partial void PartialMethod()
{
UsedMethod();
}
private static void [|UsedMethod|]() { }
}
</Document>
</Project>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册