提交 86c9874d 编写于 作者: G Gen Lu

Fix simplifier when reducing nodes inside a C# AnonymousObjectMemberDeclarator

上级 c525468e
......@@ -5132,6 +5132,46 @@ void M()
await TestInRegularAndScriptAsync(code, expected, index: 1);
}
[WorkItem(31795, "https://github.com/dotnet/roslyn/issues/31795")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
public async Task TestInAnonymousObjectMemberDeclaratorWithInferredType()
{
var code =
@"using System;
using System.Collections.Generic;
using System.Linq;
class C
{
void Test(Dictionary<int, List<Guid>> d)
{
_ = new
{
a = [|d.Values|].Where(l => l.Count == 1)
};
}
}";
var expected =
@"using System;
using System.Collections.Generic;
using System.Linq;
class C
{
void Test(Dictionary<int, List<Guid>> d)
{
Dictionary<int, List<Guid>>.ValueCollection {|Rename:values|} = d.Values;
_ = new
{
a = values.Where(l => l.Count == 1)
};
}
}";
await TestInRegularAndScriptAsync(code, expected);
}
[WorkItem(2423, "https://github.com/dotnet/roslyn/issues/2423")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
public async Task TestPickNameBasedOnArgument1()
......
......@@ -491,7 +491,7 @@ private bool ReplacementBreaksAnonymousObjectMemberDeclarator(AnonymousObjectMem
{
var originalExpressionType = this.OriginalSemanticModel.GetTypeInfo(originalAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
var newExpressionType = this.SpeculativeSemanticModel.GetTypeInfo(replacedAnonymousObjectMemberDeclarator.Expression, this.CancellationToken).Type;
return originalExpressionType != newExpressionType;
return !originalExpressionType.Equals(newExpressionType);
}
private bool ReplacementBreaksConstructorInitializer(ConstructorInitializerSyntax ctorInitializer, ConstructorInitializerSyntax newCtorInitializer)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册