提交 c0c23ab2 编写于 作者: B Balaji Krishnan

VB: Don't offer IntroduceVar for Nothing Literals

This is VB side change for internal bug 909152, similar to commit
287c94ab for C#
上级 287c94ab
......@@ -794,11 +794,10 @@ index:=1)
End Sub
<WorkItem(543529)>
<WorkItem(909152)>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)>
Public Sub TestInStatementlessConstructorParameter()
Test(
NewLines("Class C1 \n Sub New(Optional ByRef x As String = [|Nothing|]) \n End Sub \n End Class"),
NewLines("Class C1 \n Private Const {|Rename:P|} As String = Nothing \n Sub New(Optional ByRef x As String = P) \n End Sub \n End Class"))
TestMissing(NewLines("Class C1 \n Sub New(Optional ByRef x As String = [|Nothing|]) \n End Sub \n End Class"))
End Sub
<WorkItem(543650)>
......@@ -910,12 +909,10 @@ NewLines("Module M \n Sub Main() \n Dim x = <[|x|]/> \n End Sub \n End Module"))
End Sub
<WorkItem(545262)>
<WorkItem(909152)>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)>
Public Sub TestInTernaryConditional()
Test(
NewLines("Module Program \n Sub Main(args As String()) \n Dim p As Object = Nothing \n Dim Obj1 = If(New With {.a = True}.a, p, [|Nothing|]) \n End Sub \n End Module"),
NewLines("Module Program \n Sub Main(args As String()) \n Dim p As Object = Nothing \n Const {|Rename:P1|} As Object = Nothing \n Dim Obj1 = If(New With {.a = True}.a, p, P1) \n End Sub \n End Module"),
index:=2)
TestMissing(NewLines("Module Program \n Sub Main(args As String()) \n Dim p As Object = Nothing \n Dim Obj1 = If(New With {.a = True}.a, p, [|Nothing|]) \n End Sub \n End Module"))
End Sub
<WorkItem(545316)>
......@@ -1401,6 +1398,24 @@ End Module
Test(code, expected, index:=3, compareTokens:=False)
End Sub
<WorkItem(909152)>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)>
Public Sub TestMissingOnNothingLiteral()
TestMissing(
<File>
Imports System
Module Program
Sub Main(args As String())
Main([|Nothing|])
M(Nothing)
End Sub
Sub M(i As Integer)
End Sub
End Module
</File>)
End Sub
<WorkItem(1065661)>
<Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)>
Public Sub TestIntroduceVariableTextDoesntSpanLines()
......
......@@ -109,7 +109,7 @@ protected override bool CanIntroduceVariableFor(ExpressionSyntax expression)
}
// (b) For Null Literals, as AllOccurences could introduce semantic errors.
if (expression is LiteralExpressionSyntax && ((LiteralExpressionSyntax)expression).IsKind(SyntaxKind.NullLiteralExpression))
if (expression.IsKind(SyntaxKind.NullLiteralExpression))
{
return false;
}
......
......@@ -77,6 +77,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.IntroduceVariable
Return False
End If
' For Nothing Literals, AllOccurences could introduce semantic errors.
If expression.IsKind(SyntaxKind.NothingLiteralExpression) Then
Return False
End If
Return True
End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册