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

Recommend 'this' inside local functions (#27690)

上级 15978b52
......@@ -269,6 +269,79 @@ public async Task TestInStaticMethodInStaticClass()
static int Goo($$");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27028, "https://github.com/dotnet/roslyn/issues/27028")]
public async Task TestInLocalFunction()
{
await VerifyKeywordAsync(
@"class C
{
int Method()
{
void local()
{
$$
}
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27028, "https://github.com/dotnet/roslyn/issues/27028")]
public async Task TestInNestedLocalFunction()
{
await VerifyKeywordAsync(
@"class C
{
int Method()
{
void local()
{
void nested()
{
$$
}
}
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27028, "https://github.com/dotnet/roslyn/issues/27028")]
public async Task TestInLocalFunctionInStaticMethod()
{
await VerifyAbsenceAsync(
@"class C {
static int Method()
{
void local()
{
$$
}
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27028, "https://github.com/dotnet/roslyn/issues/27028")]
public async Task TestInNestedLocalFunctionInStaticMethod()
{
await VerifyAbsenceAsync(
@"class C
{
static int Method()
{
void local()
{
void nested()
{
$$
}
}
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestAfterAttribute()
{
......
......@@ -1771,6 +1771,13 @@ public static bool IsInstanceContext(this SyntaxTree syntaxTree, SyntaxToken tar
#endif
var enclosingSymbol = semanticModel.GetEnclosingSymbol(targetToken.SpanStart, cancellationToken);
while (enclosingSymbol is IMethodSymbol method && method.MethodKind == MethodKind.LocalFunction)
{
// It is allowed to reference the instance (`this`) within a local function, as long as the containing method allows it
enclosingSymbol = method.ContainingSymbol;
}
return !enclosingSymbol.IsStatic;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册