Fix VSTHRD110 firing in Expression-valued scenarios #1467
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes VSTHRD110 analyzer incorrectly firing when Task-valued lambdas are passed to methods expecting
Expression<>
parameters. In these scenarios, the lambda is converted to an expression tree (data structure) rather than being executed, so no warning should be shown.Problem
When using libraries like Moq, VSTHRD110 would incorrectly fire on legitimate code:
The lambda
x => x.InfoAsync(It.IsAny<string>())
is converted to anExpression<Func<ILogger, Task>>
for inspection by Moq, not actually executed, so VSTHRD110 should not apply.Solution
Added detection logic to
AbstractVSTHRD110ObserveResultOfAsyncCallsAnalyzer
that:IAnonymousFunctionOperation
System.Linq.Expressions.Expression<T>
via:IConversionOperation
(direct assignment:Expression<Func<T, Task>> expr = x => x.Method()
)IArgumentOperation
(method parameter:SomeMethod(x => x.Method())
where parameter isExpression<>
)Test Coverage
Added comprehensive test cases covering:
mock.Verify(x => x.InfoAsync("test"), Times.Never)
)Expression<Func<T, Task>> expr = x => x.InfoAsync("test")
)SomeMethod(x => x.InfoAsync("test"))
where parameter isExpression<>
)Edge Cases Handled
System.Linq.Expressions
namespaceFixes #1167.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
1elvsblobprodwus2177.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)2wrvsblobprodwus2180.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)31bvsblobprodwus2143.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)5o1vsblobprodwus2115.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)5zivsblobprodwus217.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)78kvsblobprodwus2152.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)8wdvsblobprodwus2137.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)9yyvsblobprodwus2157.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)abcvsblobprodwus2161.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)an0vsblobprodwus2146.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)b15vsblobprodwus2164.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)b53vsblobprodwus2154.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)cffvsblobprodwus218.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)d94vsblobprodwus2119.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dyrvsblobprodwus2173.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)fcwvsblobprodwus2113.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)h8evsblobprodwus2120.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)i01vsblobprodwus216.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)isovsblobprodwus211.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)jk4vsblobprodwus2186.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)jlovsblobprodwus2163.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)km4vsblobprodwus2183.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)mdcvsblobprodwus2159.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)nypvsblobprodwus2178.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)pkwvsblobprodwus2126.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)s0ivsblobprodwus2134.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)s8nvsblobprodwus2158.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)tn2vsblobprodwus2124.vsblob.vsassets.io
dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)v41vsblobprodwus2175.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)vd2vsblobprodwus2150.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)vipvsblobprodwus2139.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)wztvsblobprodwus2155.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)x0dvsblobprodwus2111.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)x1mvsblobprodwus2181.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)xktvsblobprodwus2141.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)xofvsblobprodwus2114.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)y1mvsblobprodwus2138.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet build src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)z2bvsblobprodwus2185.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)zaxvsblobprodwus215.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)zugvsblobprodwus2169.vsblob.vsassets.io
dotnet build --configuration Release
(dns block)dotnet restore --configfile nuget.config
(dns block)If you need me to access, download, or install something from one of these locations, you can either: