Skip to content

Commit

Permalink
Merge pull request #71288 from genlu/FixReturnAttrTarget
Browse files Browse the repository at this point in the history
Provide 'return' keyword in attribute context for accessor
  • Loading branch information
genlu authored Dec 29, 2023
2 parents a13f818 + eabb2fc commit e18df20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,20 @@ void Goo([$$
""");
}

[Fact]
public async Task TestNotInPropertyAttribute()
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71200")]
public async Task TestInPropertyAttribute()
{
await VerifyAbsenceAsync(
await VerifyKeywordAsync(
"""
class C {
int Goo { [$$
""");
}

[Fact]
public async Task TestNotInEventAttribute()
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71200")]
public async Task TestInEventAttribute()
{
await VerifyAbsenceAsync(
await VerifyKeywordAsync(
"""
class C {
event Action<int> Goo { [$$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Utilities;
using Microsoft.CodeAnalysis.Shared.Extensions;

Expand All @@ -30,7 +31,16 @@ private static bool IsAttributeContext(CSharpSyntaxContext context, Cancellation
return
context.IsMemberAttributeContext(SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations, cancellationToken) ||
(context.SyntaxTree.IsScript() && context.IsTypeAttributeContext(cancellationToken)) ||
context.IsStatementAttributeContext();
context.IsStatementAttributeContext() ||
IsAccessorAttributeContext();

bool IsAccessorAttributeContext()
{
var token = context.TargetToken;
return token.Kind() == SyntaxKind.OpenBracketToken &&
token.Parent is AttributeListSyntax &&
token.Parent.Parent is AccessorDeclarationSyntax;
}
}
}
}

0 comments on commit e18df20

Please sign in to comment.