提交 830c840f 编写于 作者: R Ravi Chande

Fix crash in VB type inferrer

One path in the VB type inferrer assumed that invocations of Select() would always have an argument list, leading to crashes. We now check that it is not null before accessing it. This is the only unguarded use of this property in the type inferrer.
Fixes  https://devdiv.visualstudio.com/DevDiv/_workitems?id=431509&_a=edit&triage=true
上级 8919c7a2
......@@ -26,8 +26,8 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.TypeInferrer
useNodeStartPosition,
typeInference.InferType(Await document.GetSemanticModelForSpanAsync(New TextSpan(node.SpanStart, 0), CancellationToken.None), node.SpanStart, objectAsDefault:=True, cancellationToken:=CancellationToken.None),
typeInference.InferType(Await document.GetSemanticModelForSpanAsync(node.Span, CancellationToken.None), node, objectAsDefault:=True, cancellationToken:=CancellationToken.None))
Dim typeSyntax = inferredType.GenerateTypeSyntax().NormalizeWhitespace()
Assert.Equal(expectedType, typeSyntax.ToString())
End Function
Private Async Function TestInClassAsync(text As String, expectedType As String) As Tasks.Task
......@@ -773,5 +773,18 @@ class C
end class"
Await TestAsync(text, "System.Boolean", testNode:=False)
End Function
<WorkItem(431509, "https://devdiv.visualstudio.com/DevDiv/_workitems?id=431509&_a=edit&triage=true")>
<Fact, Trait(Traits.Feature, Traits.Features.TypeInferenceService)>
Public Async Function InvocationWithNoArguments() As Task
Dim text =
"Module Program
Sub Main(args As String())
Dim z As IEnumerable(Of Integer)
[|z|].Select
End Sub
End Module"
Await TestAsync(text, "System.Object", testNode:=False)
End Function
End Class
End Namespace
......@@ -895,7 +895,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' T if we get a delegate as the first argument to Select/Where.
If ienumerableType IsNot Nothing AndAlso memberAccessExpression.IsParentKind(SyntaxKind.InvocationExpression) Then
Dim invocation = DirectCast(memberAccessExpression.Parent, InvocationExpressionSyntax)
If invocation.ArgumentList.Arguments.Count > 0 AndAlso
If invocation.ArgumentList IsNot Nothing AndAlso invocation.ArgumentList.Arguments.Count > 0 AndAlso
TypeOf invocation.ArgumentList.Arguments(0) Is SimpleArgumentSyntax Then
Dim argumentExpression = DirectCast(invocation.ArgumentList.Arguments(0), SimpleArgumentSyntax).Expression
Dim argumentTypes = GetTypes(argumentExpression)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册