From 426eeb9dc6065d6c43ef35968734d37fbd34e486 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 14:41:30 +0000 Subject: [PATCH 01/10] Initial plan From c686617e617f2b11f1543da67f22e61bda76e573 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 14:52:58 +0000 Subject: [PATCH 02/10] Add test to verify ParseAttributeArgumentList handles invalid input without NullReferenceException Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com> --- .../Test/Syntax/Syntax/SyntaxFactoryTests.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index bc2e73ce0a952..0e6272b793bc4 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -714,5 +714,20 @@ public void TestParseMethodsKeepParseOptionsInTheTree() var typeName = SyntaxFactory.ParseTypeName("", options: parseOptions); Assert.Same(parseOptions, typeName.SyntaxTree.Options); } + + [Fact] + public void TestParseAttributeArgumentListWithInvalidString() + { + // Regression test for issue where ParseAttributeArgumentList would throw NullReferenceException + // when given an invalid string without brackets + var result = SyntaxFactory.ParseAttributeArgumentList("somethingWithoutBrackets"); + + Assert.NotNull(result); + Assert.True(result.GetDiagnostics().Any(), "Expected diagnostics for invalid input"); + + // Verify the structure is as expected - should have missing open/close parens and errors + Assert.True(result.OpenParenToken.IsMissing); + Assert.True(result.CloseParenToken.IsMissing); + } } } From b7b47dbb23d4843e7aace819352e928832a5f359 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 14:56:17 +0000 Subject: [PATCH 03/10] Add WorkItem attribute linking test to original issue #8699 Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com> --- src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index 0e6272b793bc4..6dc03fdb69888 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -715,11 +715,11 @@ public void TestParseMethodsKeepParseOptionsInTheTree() Assert.Same(parseOptions, typeName.SyntaxTree.Options); } - [Fact] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8699")] public void TestParseAttributeArgumentListWithInvalidString() { // Regression test for issue where ParseAttributeArgumentList would throw NullReferenceException - // when given an invalid string without brackets + // when given an invalid string without brackets (parentheses) var result = SyntaxFactory.ParseAttributeArgumentList("somethingWithoutBrackets"); Assert.NotNull(result); From 5766981483cbdcdba4bb0495dbbf6d825cec11df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Oct 2025 14:57:58 +0000 Subject: [PATCH 04/10] Fix comment to consistently use 'parentheses' instead of 'brackets' Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com> --- src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index 6dc03fdb69888..99bc7049de3fb 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -719,7 +719,7 @@ public void TestParseMethodsKeepParseOptionsInTheTree() public void TestParseAttributeArgumentListWithInvalidString() { // Regression test for issue where ParseAttributeArgumentList would throw NullReferenceException - // when given an invalid string without brackets (parentheses) + // when given an invalid string without parentheses var result = SyntaxFactory.ParseAttributeArgumentList("somethingWithoutBrackets"); Assert.NotNull(result); From 0baf65f2ce26e0ba37c9a39a55f047f06e538fed Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 14 Oct 2025 17:04:32 +0200 Subject: [PATCH 05/10] Update src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs --- src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index 99bc7049de3fb..7d16dc86b66e7 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -715,7 +715,7 @@ public void TestParseMethodsKeepParseOptionsInTheTree() Assert.Same(parseOptions, typeName.SyntaxTree.Options); } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8699")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23877")] public void TestParseAttributeArgumentListWithInvalidString() { // Regression test for issue where ParseAttributeArgumentList would throw NullReferenceException From 68bf2c4a7d1c7a577f34200d734bd0dc263deda2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 14 Oct 2025 17:32:31 +0200 Subject: [PATCH 06/10] lint --- src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index 7d16dc86b66e7..c077bf4828ec8 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -721,10 +721,10 @@ 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); Assert.True(result.GetDiagnostics().Any(), "Expected diagnostics for invalid input"); - + // Verify the structure is as expected - should have missing open/close parens and errors Assert.True(result.OpenParenToken.IsMissing); Assert.True(result.CloseParenToken.IsMissing); From 7e4973ab7fd9587fba578aaec4cc5f9670220f67 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 14 Oct 2025 21:45:59 +0200 Subject: [PATCH 07/10] Add more in test --- .../Syntax/Parsing/DeclarationParsingTests.cs | 25 +++++++++++++++++++ .../Test/Syntax/Syntax/SyntaxFactoryTests.cs | 16 +----------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs index dc1a29a8411f1..e7ff32775b370 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs @@ -6,6 +6,7 @@ using System; using System.Linq; +using ICSharpCode.Decompiler.IL.Transforms; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; @@ -11132,5 +11133,29 @@ 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); + Assert.True(result.GetDiagnostics().Any(), "Expected diagnostics for invalid input"); + + // Verify the structure is as expected - should have missing open/close parens and errors + Assert.True(result.OpenParenToken.IsMissing); + Assert.True(result.CloseParenToken.IsMissing); + + UsingNode(result); + + M(SyntaxKind.AttributeArgumentList); + { + M(SyntaxKind.OpenParenToken); + M(SyntaxKind.CloseParenToken); + } + EOF(); + } } } diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index c077bf4828ec8..3e7ebf95a592f 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -8,6 +8,7 @@ using System.Globalization; using System.Linq; using System.Text; +using ICSharpCode.Decompiler.IL.Transforms; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Text; @@ -714,20 +715,5 @@ public void TestParseMethodsKeepParseOptionsInTheTree() var typeName = SyntaxFactory.ParseTypeName("", options: parseOptions); Assert.Same(parseOptions, typeName.SyntaxTree.Options); } - - [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); - Assert.True(result.GetDiagnostics().Any(), "Expected diagnostics for invalid input"); - - // Verify the structure is as expected - should have missing open/close parens and errors - Assert.True(result.OpenParenToken.IsMissing); - Assert.True(result.CloseParenToken.IsMissing); - } } } From b368bfdf7e36a67c701c04696dc971f67190bfa8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 14 Oct 2025 23:13:27 +0200 Subject: [PATCH 08/10] Update src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs --- .../CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs index e7ff32775b370..976223c145465 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs @@ -6,7 +6,6 @@ using System; using System.Linq; -using ICSharpCode.Decompiler.IL.Transforms; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; From 3461d6e2ef107131a5406748e2772e23af5b4b8e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 14 Oct 2025 23:13:43 +0200 Subject: [PATCH 09/10] Update src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs --- src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs index 3e7ebf95a592f..bc2e73ce0a952 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxFactoryTests.cs @@ -8,7 +8,6 @@ using System.Globalization; using System.Linq; using System.Text; -using ICSharpCode.Decompiler.IL.Transforms; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Text; From 611737b0e08ab7cb70fb1f568e346b13ead5fd7d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 15 Oct 2025 01:29:40 +0200 Subject: [PATCH 10/10] Change test --- .../Test/Syntax/Parsing/DeclarationParsingTests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs index 976223c145465..bc46fb8cd1cff 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs @@ -11141,11 +11141,10 @@ public void TestParseAttributeArgumentListWithInvalidString() var result = SyntaxFactory.ParseAttributeArgumentList("somethingWithoutBrackets"); Assert.NotNull(result); - Assert.True(result.GetDiagnostics().Any(), "Expected diagnostics for invalid input"); - - // Verify the structure is as expected - should have missing open/close parens and errors - Assert.True(result.OpenParenToken.IsMissing); - Assert.True(result.CloseParenToken.IsMissing); + result.GetDiagnostics().Verify( + // (1,1): error CS1073: Unexpected token 'somethingWithoutBrackets' + // somethingWithoutBrackets + Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("somethingWithoutBrackets").WithLocation(1, 1)); UsingNode(result);