diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs index dc1a29a8411f1..bc46fb8cd1cff 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs @@ -11132,5 +11132,28 @@ public void Class_IncompleteArgumentList_06(bool @struct) } EOF(); } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23877")] + public void TestParseAttributeArgumentListWithInvalidString() + { + // Regression test for issue where ParseAttributeArgumentList would throw NullReferenceException + // when given an invalid string without parentheses + var result = SyntaxFactory.ParseAttributeArgumentList("somethingWithoutBrackets"); + + Assert.NotNull(result); + result.GetDiagnostics().Verify( + // (1,1): error CS1073: Unexpected token 'somethingWithoutBrackets' + // somethingWithoutBrackets + Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("somethingWithoutBrackets").WithLocation(1, 1)); + + UsingNode(result); + + M(SyntaxKind.AttributeArgumentList); + { + M(SyntaxKind.OpenParenToken); + M(SyntaxKind.CloseParenToken); + } + EOF(); + } } }