未验证 提交 6c3bfeda 编写于 作者: J Julien Couvreur 提交者: GitHub

AddParameter should handle and bail out on omitted argument (#23933)

上级 ee2a411f
......@@ -13,6 +13,25 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.AddParameter
Return (Nothing, New VisualBasicAddParameterCodeFixProvider())
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParameter)>
<WorkItem(23927, "https://github.com/dotnet/roslyn/issues/23927")>
Public Async Function TestMissingOnOmittedArgument() As Task
Await TestMissingAsync(
"Public Module Module1
Private Class C
Public Sub New(Arg1 As Integer)
End Sub
Public Sub New(Arg1 As Integer, Arg2 As Integer)
End Sub
End Class
Public Sub Main()
Dim x = New [|C|](, 0)
End Sub
End Module")
End Function
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParameter)>
Public Async Function TestMissingWithImplicitConstructor() As Task
Await TestMissingAsync(
......
......@@ -442,10 +442,14 @@ private int NonParamsParameterCount(IMethodSymbol method)
// Now check the type of the argument versus the type of the parameter. If they
// don't match, then this is the argument we should make the parameter for.
var expressionOfArgumment = syntaxFacts.GetExpressionOfArgument(argument);
var argumentTypeInfo = semanticModel.GetTypeInfo(expressionOfArgumment);
var isNullLiteral = syntaxFacts.IsNullLiteralExpression(expressionOfArgumment);
var isDefaultLiteral = syntaxFacts.IsDefaultLiteralExpression(expressionOfArgumment);
var expressionOfArgument = syntaxFacts.GetExpressionOfArgument(argument);
if (expressionOfArgument is null)
{
return null;
}
var argumentTypeInfo = semanticModel.GetTypeInfo(expressionOfArgument);
var isNullLiteral = syntaxFacts.IsNullLiteralExpression(expressionOfArgument);
var isDefaultLiteral = syntaxFacts.IsDefaultLiteralExpression(expressionOfArgument);
if (argumentTypeInfo.Type == null && argumentTypeInfo.ConvertedType == null)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册