提交 4dc4f725 编写于 作者: D Dmitry Kischenko

#17177 - Unresolvable conflict not indicated when renaming identifier. (Tests)

上级 7f10dedd
......@@ -466,5 +466,140 @@ namespace ConsoleApplication1
result.AssertLabeledSpansAre("stmt2", "this.list = list.ToList();", RelatedLocationType.ResolvedReferenceConflict)
End Using
End Sub
<Fact>
<Trait(Traits.Feature, Traits.Features.Rename)>
<WorkItem(17177, "https://github.com/dotnet/roslyn/issues/17177")>
Public Sub ConflictsBetweenSwitchCaseStatementsWithoutBlocks()
Using result = RenameEngineResult.Create(_outputHelper,
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class Test
{
static void Main()
{
switch (true)
{
case true:
object {|stmt1:$$i|} = null;
break;
case false:
object {|stmt2:j|} = null;
break;
}
}
}
</Document>
</Project>
</Workspace>, renameTo:="j")
result.AssertLabeledSpansAre("stmt1", "j", RelatedLocationType.NoConflict)
result.AssertLabeledSpansAre("stmt2", "j", RelatedLocationType.UnresolvableConflict)
End Using
End Sub
<Fact>
<Trait(Traits.Feature, Traits.Features.Rename)>
<WorkItem(17177, "https://github.com/dotnet/roslyn/issues/17177")>
Public Sub NoConflictsBetweenSwitchCaseStatementsWithBlocks()
Using result = RenameEngineResult.Create(_outputHelper,
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class Test
{
static void Main()
{
switch (true)
{
case true:
{
object {|stmt1:$$i|} = null;
break;
}
case false:
{
object j = null;
break;
}
}
}
}
</Document>
</Project>
</Workspace>, renameTo:="j")
result.AssertLabeledSpansAre("stmt1", "j", RelatedLocationType.NoConflict)
End Using
End Sub
<Fact>
<Trait(Traits.Feature, Traits.Features.Rename)>
<WorkItem(17177, "https://github.com/dotnet/roslyn/issues/17177")>
Public Sub NoConflictsBetweenSwitchCaseStatementFirstStatementWithBlock()
Using result = RenameEngineResult.Create(_outputHelper,
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class Test
{
static void Main()
{
switch (true)
{
case true:
{
object {|stmt1:$$i|} = null;
break;
}
case false:
object {|stmt2:j|} = null;
break;
}
}
}
</Document>
</Project>
</Workspace>, renameTo:="j")
result.AssertLabeledSpansAre("stmt1", "j", RelatedLocationType.NoConflict)
result.AssertLabeledSpansAre("stmt2", "j", RelatedLocationType.UnresolvableConflict)
End Using
End Sub
<Fact>
<Trait(Traits.Feature, Traits.Features.Rename)>
<WorkItem(17177, "https://github.com/dotnet/roslyn/issues/17177")>
Public Sub NoConflictsBetweenSwitchCaseStatementSecondStatementWithBlock()
Using result = RenameEngineResult.Create(_outputHelper,
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class Test
{
static void Main()
{
switch (true)
{
case true:
object {|stmt1:$$i|} = null;
break;
case false:
{
object {|stmt2:j|} = null;
break;
}
}
}
}
</Document>
</Project>
</Workspace>, renameTo:="j")
result.AssertLabeledSpansAre("stmt1", "j", RelatedLocationType.NoConflict)
result.AssertLabeledSpansAre("stmt2", "j", RelatedLocationType.UnresolvableConflict)
End Using
End Sub
End Class
End Namespace
......@@ -187,19 +187,18 @@ public override void VisitSwitchStatement(SwitchStatementSyntax node)
{
var tokens = new List<SyntaxToken>();
var statements = node.ChildNodes()
.Where(x => x.IsKind(SyntaxKind.SwitchSection))
.SelectMany(x => x.ChildNodes().Where(n => n.IsKind(SyntaxKind.LocalDeclarationStatement)));
var statements = node.ChildNodes().Where(x => x.IsKind(SyntaxKind.SwitchSection)).SelectMany(x => x.ChildNodes());
// We want to collect any variable declarations that are in the block
// before visiting nested statements
foreach (var statement in statements)
{
var declarationStatement = (LocalDeclarationStatementSyntax)statement;
foreach (var declarator in declarationStatement.Declaration.Variables)
if (statement.Kind() == SyntaxKind.LocalDeclarationStatement)
{
tokens.Add(declarator.Identifier);
var declarationStatement = (LocalDeclarationStatementSyntax)statement;
foreach (var declarator in declarationStatement.Declaration.Variables)
{
tokens.Add(declarator.Identifier);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册