提交 3cafe388 编写于 作者: S Sam Harwell

Fix failure to handle expression-bodied local functions

上级 2b5209ac
......@@ -348,18 +348,24 @@ void X()
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAssignOutParameters)]
public async Task TestMissingForLocalFunctionExpressionBody()
{
// Not desirable. Happens because error is not reported on expr-body
// like for lambdas.
var code = @"class C
await VerifyCS.VerifyCodeFixAsync(
@"class C
{
void X()
{
char {|CS0177:D|}(out int i) => 'a';
D(out _);
}
}";
}",
@"class C
{
void X()
{
char D(out int i) { i = 0; return 'a'; }
await VerifyCS.VerifyCodeFixAsync(code, code);
D(out _);
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAssignOutParameters)]
......
......@@ -42,6 +42,14 @@ protected override void TryRegisterFix(CodeFixContext context, Document document
{
var generator = editor.Generator;
if (exprOrStatement is LocalFunctionStatementSyntax { ExpressionBody: { } localFunctionExpressionBody })
{
// Expression-bodied local functions report CS0177 on the method name instead of the expression.
// Reassign exprOrStatement so the code fix implementation works as it does for other expression-bodied
// members.
exprOrStatement = localFunctionExpressionBody.Expression;
}
var parent = exprOrStatement.Parent;
if (parent.IsEmbeddedStatementOwner())
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册