Closed penenkel closed 1 year ago
It is my opinion that applying a CodeFix should not cause syntax errors
Well, sadly, your opinion doesn't align with how the compiler team has designed it. Sure, if applying a CodeFix results in a syntax error, that's bad, but it's never claimed that it wouldn't do that. On the contrary, it's specifically allowed to do so for the case where the developer intends to refactor further after the fix is applied.
In fact, if the fix was not suggested due to resulting in errors, you'd end up in a world where CodeFixes are almost never used because they're suggested far too little to be useful because they're being far too conservative about when they should be suggested.
hm, well, I guess that makes kind of sense. Too bad.
Version Used: VS2019.3.9 - .NET Core 3.0 ConsoleApp
Issue It is my opinion that applying a CodeFix should not cause syntax errors (assuming the code was valid before). Under that assumption I find it rather annoying that the CodeFix for CS1998 does not respect the usages of the methods it modifies (at least not all), resulting in syntax errors.
Steps to Reproduce: Consider the following example
which is fixed to:
which shows that only one of the usage kinds has been adapted correctly.
Expected Behavior: As stated above: I would expect that a CodeFix does not produce incorrect code. Obviously this is not so trivial to fix. In case 2 it would probably be OK to just remove the> func = () => Task.FromResult("abc")`` or similar.
.Result
(ignoring the fact that such a usage should better not exist at all). But as soon as the method is stored in a variable one probably should not modify the signature at all and instead use something likereturn Task.FromResult("abc")
within the method. (This is especially relevant when used with lambda functions likeFunc<Task<string>> func = async () => "abc"
, which should probably transformed to `Func<Task