diff --git a/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs b/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs index 8f2a26a7b2a4695b253bebe5b0153a4bb1a3dfea..a11454b09c5f8ef629d42ecde3fd78e7687494a1 100644 --- a/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs +++ b/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs @@ -490,6 +490,7 @@ static int Method() }"); } + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] [WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")] public async Task TestInNestedLambdaExpressionInAnonymousMethod() { @@ -509,6 +510,7 @@ int Method() }"); } + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] [WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")] public async Task TestInNestedAnonymousInLambdaExpression() { @@ -528,6 +530,7 @@ int Method() }"); } + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] [WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")] public async Task TestInNestedAnonymousMethodInLambdaExpressionInStaticMethod() { @@ -547,6 +550,7 @@ static int Method() }"); } + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] [WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")] public async Task TestInNestedLambdaExpressionInAnonymousMethodInStaticMethod() { @@ -566,6 +570,34 @@ static int Method() }"); } + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] + [WorkItem(27923, "https://github.com/dotnet/roslyn/issues/27923")] + public async Task TestInNestedLambdaExpressionInAProperty() + { + 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 TestInNestedLambdaExpressionInAStaticProperty() + { + await VerifyAbsenceAsync( +@"class C +{ + static Action A + { + get { return delegate { $$ } } + } +}"); + } + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task TestAfterAttribute() { diff --git a/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs b/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs index 8fade51207c3bb6a1080270b5d603e616b7ca00c..749597e4cf5d1fcf59d0e2e2b2e69d5175ac01ba 100644 --- a/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs +++ b/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs @@ -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 && enclosingSymbol.ContainingSymbol is IMethodSymbol) + while (enclosingSymbol is IMethodSymbol && enclosingSymbol.ContainingSymbol is IMethodSymbol) { // It is allowed to reference the instance (`this`) within a local function or anonymous function, as long as the containing method allows it - enclosingSymbol = method.ContainingSymbol; + enclosingSymbol = enclosingSymbol.ContainingSymbol; } return !enclosingSymbol.IsStatic;