未验证 提交 c0c192da 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #45150 from Kuinox/master

Fix MakeMethodAsynchronous on ValueTask without generics.
......@@ -959,6 +959,47 @@ async ValueTask<int> Test()
await TestInRegularAndScriptAsync(initial, expected);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodAsynchronous)]
public async Task AwaitInValueTaskWithoutGenericMethod()
{
var initial =
@"using System;
using System.Threading.Tasks;
namespace System.Threading.Tasks {
struct ValueTask
{
}
}
class Program
{
ValueTask Test()
{
[|await Task.Delay(1);|]
}
}";
var expected =
@"using System;
using System.Threading.Tasks;
namespace System.Threading.Tasks {
struct ValueTask
{
}
}
class Program
{
async ValueTask Test()
{
await Task.Delay(1);
}
}";
await TestInRegularAndScriptAsync(initial, expected);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsMakeMethodAsynchronous)]
[WorkItem(14133, "https://github.com/dotnet/roslyn/issues/14133")]
public async Task AddAsyncInLocalFunction()
......
......@@ -12,6 +12,7 @@ internal abstract partial class AbstractMakeMethodAsynchronousCodeFixProvider
{
public readonly INamedTypeSymbol _taskType;
public readonly INamedTypeSymbol _taskOfTType;
public readonly INamedTypeSymbol _valueTaskType;
public readonly INamedTypeSymbol _valueTaskOfTTypeOpt;
public readonly INamedTypeSymbol _iEnumerableOfTType;
......@@ -24,6 +25,7 @@ internal KnownTypes(Compilation compilation)
{
_taskType = compilation.TaskType();
_taskOfTType = compilation.TaskOfTType();
_valueTaskType = compilation.ValueTaskType();
_valueTaskOfTTypeOpt = compilation.ValueTaskOfTType();
_iEnumerableOfTType = compilation.IEnumerableOfTType();
......
......@@ -204,6 +204,11 @@ protected static bool IsTaskLike(ITypeSymbol returnType, KnownTypes knownTypes)
return true;
}
if (returnType.Equals(knownTypes._valueTaskType))
{
return true;
}
if (returnType.OriginalDefinition.Equals(knownTypes._taskOfTType))
{
return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册