未验证 提交 15458882 编写于 作者: I Ivan Basov 提交者: GitHub

Remove this recommendation for anonymous functions in static methods

......@@ -342,6 +342,327 @@ void nested()
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethod()
{
await VerifyKeywordAsync(
@"class C
{
int Method()
{
Action a = delegate
{
$$
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInNestedAnonymousMethod()
{
await VerifyKeywordAsync(
@"class C
{
int Method()
{
Action a = delegate
{
Action b = delegate
{
$$
};
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInStaticMethod()
{
await VerifyAbsenceAsync(
@"class C
{
static int Method()
{
Action a = delegate
{
$$
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInNestedAnonymousMethodInStaticMethod()
{
await VerifyAbsenceAsync(
@"class C
{
static int Method()
{
Action a = delegate
{
Action b = delegate
{
$$
};
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInLambdaExpression()
{
await VerifyKeywordAsync(
@"class C
{
int Method()
{
Action a = () =>
{
$$
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInNestedLambdaExpression()
{
await VerifyKeywordAsync(
@"class C
{
int Method()
{
Action a = () =>
{
Action b = () =>
{
$$
};
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInLambdaExpressionInStaticMethod()
{
await VerifyAbsenceAsync(
@"class C
{
static int Method()
{
Action a = () =>
{
$$
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInNestedLambdaExpressionInStaticMethod()
{
await VerifyAbsenceAsync(
@"class C
{
static int Method()
{
Action a = () =>
{
Action b = () =>
{
$$
};
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInNestedLambdaExpressionInAnonymousMethod()
{
await VerifyKeywordAsync(
@"class C
{
int Method()
{
Action a = delegate
{
Action b = () =>
{
$$
};
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInNestedAnonymousInLambdaExpression()
{
await VerifyKeywordAsync(
@"class C
{
int Method()
{
Action a = () =>
{
Action b = delegate
{
$$
};
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInNestedAnonymousMethodInLambdaExpressionInStaticMethod()
{
await VerifyAbsenceAsync(
@"class C
{
static int Method()
{
Action a = () =>
{
Action b = delegate
{
$$
};
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInNestedLambdaExpressionInAnonymousMethodInStaticMethod()
{
await VerifyAbsenceAsync(
@"class C
{
static int Method()
{
Action a = delegate
{
Action b = () =>
{
$$
};
};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInAProperty()
{
await VerifyKeywordAsync(
@"class C
{
Action A
{
get { return delegate { $$ } }
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInAPropertyInitializer()
{
await VerifyKeywordAsync(
@"class C
{
Action B { get; } = delegate { $$ }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInAExpressionProperty()
{
await VerifyKeywordAsync(
@"class C
{
Action A => delegate { $$ }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInAFieldInitializer()
{
await VerifyKeywordAsync(
@"class C
{
Action A = delegate { $$ }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInAStaticProperty()
{
await VerifyAbsenceAsync(
@"class C
{
static Action A
{
get { return delegate { $$ } }
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInAStaticPropertyInitializer()
{
await VerifyAbsenceAsync(
@"class C
{
static Action B { get; } = delegate { $$ }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInAStaticExpressionProperty()
{
await VerifyAbsenceAsync(
@"class C
{
static Action A => delegate { $$ }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")]
public async Task TestInAnonymousMethodInAStaticFieldInitializer()
{
await VerifyAbsenceAsync(
@"class C
{
static Action A = delegate { $$ }
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestAfterAttribute()
{
......
......@@ -1772,10 +1772,10 @@ public static bool IsInstanceContext(this SyntaxTree syntaxTree, SyntaxToken tar
var enclosingSymbol = semanticModel.GetEnclosingSymbol(targetToken.SpanStart, cancellationToken);
while (enclosingSymbol is IMethodSymbol method && method.MethodKind == MethodKind.LocalFunction)
while (enclosingSymbol is IMethodSymbol method && (method.MethodKind == MethodKind.LocalFunction || method.MethodKind == MethodKind.AnonymousFunction))
{
// It is allowed to reference the instance (`this`) within a local function, as long as the containing method allows it
enclosingSymbol = method.ContainingSymbol;
// It is allowed to reference the instance (`this`) within a local function or anonymous function, as long as the containing method allows it
enclosingSymbol = enclosingSymbol.ContainingSymbol;
}
return !enclosingSymbol.IsStatic;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册