Add code fix provider for VSTHRD109#397
Conversation
| await Verify.VerifyCodeFixAsync(test, expected, fix); | ||
| } | ||
|
|
||
| [Fact(Skip = "Fails because the semantic model claims the anonymous func returns Task instead of Task<int>. We should probably skip that check and always preserve return statements.")] |
There was a problem hiding this comment.
💡 This may work in newer versions of Roslyn with later language versions (bestest betterness). If the underlying issue is the inability to distinguish between Task.Run(Func<Task>) and Task.Run<TResult>(Func<Task<TResult>>), you can force a disambiguation in the test by calling Task.Run<int> instead of just Task.Run.
There was a problem hiding this comment.
Yes, using Task.Run<int> does resolve the issue (see the test directly above this one, on which I applied that workaround).
Interestingly though, although this compiles:
Task<int> t = Task.Run(() => Task.FromResult(1));Even in that case, which compiles, Roslyn still claims that the delegate returns Task. Yet if it really did, the result couldn't be assigned to Task<int> as I did. So what's up with that? Would 'bestest betterness' actually solve this?
There was a problem hiding this comment.
Even in that case, which compiles,
Are you compiling with the same version of Roslyn as you are using to run the tests?
There was a problem hiding this comment.
No. I compile the analyzers against Roslyn 1.2, and the tests run with 2.3. Evidently the dependency on the new Roslyn test framework bumped up the version of Roslyn I'm testing with.
How does that affect this investigation?
There was a problem hiding this comment.
Evidently the dependency on the new Roslyn test framework bumped up the version of Roslyn I'm testing with.
This shouldn't be the case. The test framework is compiled against Roslyn 1.0.1. The version of Roslyn used for testing is controlled by the following line:
Git blame indicates this was updated to Roslyn 2.3.2 in #190.
There was a problem hiding this comment.
I see. I can certainly try to match the versions up (presumably by rolling back the version in the tests). What do you predict will happen? Will it resolve the issue? If so, why?
…fad15 (#397) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This required some of the same code fixer functionality already found in the VSTHRD010 code fixer, so a few chunks of code got moved from that fixer into the Utils class.
There are several tested scenarios, but the crux of the fix is that it changes this:
to this:
Note that the code fix automatically finds JTF instance(s) to use (the user picks the one from the fix list), and automatically finds any local
CancellationTokento propagate into the switch method call.Closes #316