Skip to content

Commit 7be4a33

Browse files
committed
Merge pull request #1954 from Noryoko/fix-1937
Fix SA1606 analyzer crashes with incomplete member
2 parents d391039 + cf3793f commit 7be4a33

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/DocumentationRules/SA1606UnitTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,28 @@ public void MethodName()
745745
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
746746
}
747747

748+
[Fact]
749+
public async Task TestIncompleteMemberAsync()
750+
{
751+
var testCode = @"
752+
class Class1
753+
{
754+
/// <include file='ClassWithSummary.xml' path='/Class1/MethodName/*'/>
755+
public string MethodName
756+
}
757+
";
758+
759+
var expected = new DiagnosticResult
760+
{
761+
Id = "CS1002",
762+
Severity = DiagnosticSeverity.Error,
763+
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 5, 29) },
764+
Message = "; expected"
765+
};
766+
767+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
768+
}
769+
748770
/// <inheritdoc/>
749771
protected override Project CreateProject(string[] sources, string language = "C#", string[] filenames = null)
750772
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/ElementDocumentationSummaryBase.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,12 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, SyntaxNode nod
233233
if (relevantXmlElement != null)
234234
{
235235
var declaration = context.SemanticModel.GetDeclaredSymbol(node, context.CancellationToken);
236-
var rawDocumentation = declaration?.GetDocumentationCommentXml(expandIncludes: true, cancellationToken: context.CancellationToken);
236+
if (declaration == null)
237+
{
238+
return;
239+
}
240+
241+
var rawDocumentation = declaration.GetDocumentationCommentXml(expandIncludes: true, cancellationToken: context.CancellationToken);
237242
completeDocumentation = XElement.Parse(rawDocumentation, LoadOptions.None);
238243
if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.InheritdocXmlTag))
239244
{

0 commit comments

Comments
 (0)