Skip to content
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 @@ -205,7 +205,7 @@ private void AnalyzeAwaitExpression(SyntaxNodeAnalysisContext context)
containingFunc ??= CSharpUtils.GetContainingFunction(focusedExpression);
if (containingFunc.Value.BlockOrExpression is not null &&
CSharpUtils.FindAssignedValuesWithin(containingFunc.Value.BlockOrExpression, semanticModel, local, cancellationToken).Any(
v => v is ObjectCreationExpressionSyntax or ImplicitObjectCreationExpressionSyntax or InvocationExpressionSyntax))
v => v is ObjectCreationExpressionSyntax or ImplicitObjectCreationExpressionSyntax or InvocationExpressionSyntax or AwaitExpressionSyntax { Expression: InvocationExpressionSyntax }))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,31 @@ static async Task ListenAndWait()
await CSVerify.VerifyAnalyzerAsync(test);
}

[Fact]
public async Task DoNotReportWarningWhenAwaitingTaskPropertyOfObjectReturnedFromAsyncMethodViaLocal()
{
var test = """
using System.Threading.Tasks;

class JsonRpc
{
internal static Task<JsonRpc> AttachAsync() => throw new System.NotImplementedException();

internal Task Completion { get; }
}

class Tests
{
static async Task ListenAndWait()
{
var jsonRpc = await JsonRpc.AttachAsync();
await jsonRpc.Completion;
}
}
""";
await CSVerify.VerifyAnalyzerAsync(test);
}

[Fact]
public async Task ReportWarningWhenAwaitingTaskPropertyThatWasNotSetInContext()
{
Expand Down