Skip to content

Commit

Permalink
Merge pull request #293 from AArnott/fixReturnAsync
Browse files Browse the repository at this point in the history
Fix VSTHRD110 to not report warnings on "return DoAsync()"
  • Loading branch information
AArnott authored Jun 7, 2018
2 parents fd38f73 + fdc45a7 commit d0adeab
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,49 @@ void OtherMethod(Task t) { }
this.VerifyCSharpDiagnostic(test);
}

[Fact]
public void ReturnStatement_ProducesNoDiagnostic()
{
var test = @"
using System.Threading.Tasks;
class Test {
Task Foo()
{
return BarAsync();
}
Task BarAsync() => null;
void OtherMethod(Task t) { }
}
";

this.VerifyCSharpDiagnostic(test);
}

[Fact]
public void ContinueWith_ProducesDiagnostic()
{
var test = @"
using System.Threading.Tasks;
class Test {
void Foo()
{
BarAsync().ContinueWith(_ => { }); // ContinueWith returns the dropped task
}
Task BarAsync() => null;
void OtherMethod(Task t) { }
}
";

this.expect = this.CreateDiagnostic(7, 20, 12);
this.VerifyCSharpDiagnostic(test, this.expect);
}

[Fact]
public void AsyncMethod_ProducesNoDiagnostic()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void AnalyzeInvocation(SyntaxNodeAnalysisContext context)

// Only consider invocations that are direct statements. Otherwise, we assume their
// result is awaited, assigned, or otherwise consumed.
if (invocation.Parent is StatementSyntax)
if (invocation.Parent?.GetType().Equals(typeof(ExpressionStatementSyntax)) ?? false)
{
var methodSymbol = context.SemanticModel.GetSymbolInfo(context.Node).Symbol as IMethodSymbol;
var returnedSymbol = methodSymbol?.ReturnType;
Expand Down

0 comments on commit d0adeab

Please sign in to comment.