Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide 'return' keyword in attribute context for accessor #71288

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
}
Loading