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

Fix VSTHRD110 to not report warnings on "return DoAsync()" #293

Merged
merged 1 commit into from
Jun 7, 2018
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 @@ -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