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

Don't emit CA1849 for nameof expressions #7010

Merged
merged 1 commit into from
Oct 30, 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 @@ -137,7 +137,11 @@ public override void Initialize(AnalysisContext context)
}
else
{
InspectAndReportBlockingMemberAccess(context, ((IPropertyReferenceOperation)context.Operation).Property, syncBlockingSymbols, SymbolKind.Property);
var propertyReferenceOperation = (IPropertyReferenceOperation)context.Operation;
if (propertyReferenceOperation.Parent is not INameOfOperation)
{
InspectAndReportBlockingMemberAccess(context, propertyReferenceOperation.Property, syncBlockingSymbols, SymbolKind.Property);
}
}
}
}, OperationKind.Invocation, OperationKind.PropertyReference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,27 @@ public async Task RunAsync(IDbContextFactory<DbContext> factory) {
}.RunAsync();
}

[Theory]
[InlineData("Task<object>.Result")]
[InlineData("ValueTask<object>.Result")]
[WorkItem(6993, "https://github.com/dotnet/roslyn-analyzers/issues/6993")]
public Task WhenUsingNameOf_NoDiagnostic(string taskExpression)
{
var code = $$"""
using System.Threading.Tasks;

class Test
{
public async Task<string> Foo()
{
await Task.CompletedTask;
return nameof({{taskExpression}});
}
}
""";
return VerifyCS.VerifyAnalyzerAsync(code);
}

private static async Task CreateCSTestAndRunAsync(string testCS)
{
var csTestVerify = new VerifyCS.Test
Expand Down