Skip to content

Commit f34bd02

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

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
@@ -766,6 +766,28 @@ public class ClassName
766766
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
767767
}
768768

769+
[Fact]
770+
public async Task TestIncompleteMemberAsync()
771+
{
772+
var testCode = @"
773+
class Class1
774+
{
775+
/// <include file='ClassWithSummary.xml' path='/Class1/MethodName/*'/>
776+
public string MethodName
777+
}
778+
";
779+
780+
var expected = new DiagnosticResult
781+
{
782+
Id = "CS1002",
783+
Severity = DiagnosticSeverity.Error,
784+
Locations = new[] { new DiagnosticResultLocation("Test0.cs", 5, 29) },
785+
Message = "; expected"
786+
};
787+
788+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
789+
}
790+
769791
/// <inheritdoc/>
770792
protected override Project CreateProject(string[] sources, string language = "C#", string[] filenames = null)
771793
{

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ private void HandleDeclaration(SyntaxNodeAnalysisContext context, SyntaxNode nod
228228
if (relevantXmlElement != null)
229229
{
230230
var declaration = context.SemanticModel.GetDeclaredSymbol(node, context.CancellationToken);
231-
var rawDocumentation = declaration?.GetDocumentationCommentXml(expandIncludes: true, cancellationToken: context.CancellationToken);
231+
if (declaration == null)
232+
{
233+
return;
234+
}
235+
236+
var rawDocumentation = declaration.GetDocumentationCommentXml(expandIncludes: true, cancellationToken: context.CancellationToken);
232237
completeDocumentation = XElement.Parse(rawDocumentation, LoadOptions.None);
233238
}
234239
}

0 commit comments

Comments
 (0)