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

Fix semantic model on deconstruction-foreach expression (#22878)

上级 ee88efd6
......@@ -249,7 +249,7 @@ private BoundForEachStatement BindForEachPartsWorker(DiagnosticBag diagnostics,
var variables = node.Variable;
if (variables.IsDeconstructionLeft())
{
var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, collectionEscape, iterationVariableType);
var valuePlaceholder = new BoundDeconstructValuePlaceholder(_syntax.Expression, collectionEscape, iterationVariableType) { WasCompilerGenerated = true } ;
DeclarationExpressionSyntax declaration = null;
ExpressionSyntax expression = null;
BoundDeconstructionAssignmentOperator deconstruction = BindDeconstruction(
......
......@@ -3869,6 +3869,35 @@ .maxstack 3
}");
}
[Fact]
[WorkItem(22495, "https://github.com/dotnet/roslyn/issues/22495")]
public void ForEachCollectionSymbol()
{
string source = @"
using System.Collections.Generic;
class Deconstructable
{
void M(IEnumerable<Deconstructable> x)
{
foreach (var (y1, y2) in x)
{
}
}
void Deconstruct(out int i, out int j) { i = 0; j = 0; }
}
";
var compilation = CreateStandardCompilation(source, references: s_valueTupleRefs);
var tree = compilation.SyntaxTrees.First();
var model = compilation.GetSemanticModel(tree);
var collection = tree.GetRoot().DescendantNodes().OfType<ForEachVariableStatementSyntax>().Single().Expression;
Assert.Equal("x", collection.ToString());
var symbol = model.GetSymbolInfo(collection).Symbol;
Assert.Equal(SymbolKind.Parameter, symbol.Kind);
Assert.Equal("x", symbol.Name);
Assert.Equal("System.Collections.Generic.IEnumerable<Deconstructable> x", symbol.ToTestDisplayString());
}
[Fact]
public void ForEachIEnumerableDeclarationWithNesting()
{
......
......@@ -55,6 +55,33 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename
End Using
End Function
<WpfFact>
<Trait(Traits.Feature, Traits.Features.Rename)>
<WorkItem(22495, "https://github.com/dotnet/roslyn/issues/22495")>
Public Async Function RenameDeconstructionForeachCollection() As Task
Using workspace = CreateWorkspaceWithWaiter(
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document><![CDATA[
using System.Collections.Generic;
class Deconstructable
{
void M(IEnumerable<Deconstructable> [|$$x|])
{
foreach (var (y1, y2) in [|x|])
{
}
}
void Deconstruct(out int i, out int j) { i = 0; j = 0; }
}
]]></Document>
</Project>
</Workspace>)
Await VerifyRenameOptionChangedSessionCommit(workspace, "x", "change", renameOverloads:=True)
End Using
End Function
<WpfFact>
<Trait(Traits.Feature, Traits.Features.Rename)>
<WorkItem(540120, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540120")>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册