Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1310,14 +1310,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' Lines: 16304 - 16304
' ParenthesizedArgumentList .Parser::ParseParenthesizedArguments( [ _Inout_ bool& ErrorInConstruct ] )
Friend Function ParseParenthesizedArguments(Optional RedimOrNewParent As Boolean = False, Optional attributeListParent As Boolean = False) As ArgumentListSyntax
Debug.Assert(CurrentToken.Kind = SyntaxKind.OpenParenToken, "should be at tkLParen.")

Dim arguments As CodeAnalysis.Syntax.InternalSyntax.SeparatedSyntaxList(Of ArgumentSyntax) = Nothing
Dim openParen As PunctuationSyntax = Nothing
Dim closeParen As PunctuationSyntax = Nothing

Debug.Assert(CurrentToken.Kind = SyntaxKind.OpenParenToken)
TryGetTokenAndEatNewLine(SyntaxKind.OpenParenToken, openParen)
' Try to get the opening parenthesis, create a missing one if not found
If Not TryGetTokenAndEatNewLine(SyntaxKind.OpenParenToken, openParen) Then
openParen = InternalSyntaxFactory.MissingPunctuation(SyntaxKind.OpenParenToken)
openParen = ReportSyntaxError(openParen, ERRID.ERR_ExpectedLparen)
End If

Dim unexpected As GreenNode = Nothing
arguments = ParseArguments(unexpected, RedimOrNewParent, attributeListParent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,30 @@ Integer
Dim typeName = SyntaxFactory.ParseTypeName("", options:=parseOptions)
Assert.Same(parseOptions, typeName.SyntaxTree.Options)
End Sub

<Fact>
Public Shared Sub TestParseArgumentListWithoutParentheses()
' This should not throw NullReferenceException or assertion failure
' when input lacks parentheses
Dim result = SyntaxFactory.ParseArgumentList("42")

' Should still produce a valid ArgumentListSyntax with errors
Assert.NotNull(result)
Assert.True(result.ContainsDiagnostics)

' Should have an error for missing opening parenthesis
Dim errors = result.GetDiagnostics().ToArray()
Assert.True(errors.Length > 0, "Expected diagnostic errors for missing parentheses")

' Verify that the parse produces a valid tree with missing tokens
Assert.NotNull(result.OpenParenToken)
Assert.True(result.OpenParenToken.IsMissing)

' Test with parentheses - should work correctly
Dim resultWithParens = SyntaxFactory.ParseArgumentList("(42)")
Assert.NotNull(resultWithParens)
Assert.Equal("(42)", resultWithParens.ToString())
Assert.False(resultWithParens.ContainsDiagnostics)
End Sub
End Class
End Namespace