Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
1de61162
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1de61162
编写于
4月 29, 2020
作者:
A
Allison Chou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix async bug and add tests
上级
05779838
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
87 addition
and
4 deletion
+87
-4
src/EditorFeatures/CSharpTest/CodeActions/IntroduceVariable/IntroduceVariableTests.cs
...t/CodeActions/IntroduceVariable/IntroduceVariableTests.cs
+67
-2
src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs
...Variable/CSharpIntroduceVariableService_IntroduceLocal.cs
+16
-2
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ICompilationExtensions.cs
...nsions/Compiler/Core/Extensions/ICompilationExtensions.cs
+4
-0
未找到文件。
src/EditorFeatures/CSharpTest/CodeActions/IntroduceVariable/IntroduceVariableTests.cs
浏览文件 @
1de61162
...
...
@@ -7594,6 +7594,12 @@ public async Task TestMissingReturnStatementInAsyncValueTaskMethod()
@"using System;
using System.Threading.Tasks;
namespace System.Threading.Tasks {
struct ValueTask
{
}
}
class Program
{
void M()
...
...
@@ -7608,14 +7614,20 @@ async ValueTask M2()
@"using System;
using System.Threading.Tasks;
namespace System.Threading.Tasks {
struct ValueTask
{
}
}
class Program
{
void M()
{
Func<int, ValueTask> f = async x =>
{
ValueTask {|Rename:
t
ask|} = M2();
await
t
ask;
ValueTask {|Rename:
valueT
ask|} = M2();
await
valueT
ask;
};
}
...
...
@@ -7662,6 +7674,59 @@ async Task<int> M2()
{
return 0;
}
}"
);
}
[
WorkItem
(
40745
,
"https://github.com/dotnet/roslyn/issues/40745"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsIntroduceVariable
)]
public
async
Task
TestMissingReturnStatementInAsyncValueTaskTypeMethod
()
{
await
TestInRegularAndScriptAsync
(
@"using System;
using System.Threading.Tasks;
namespace System.Threading.Tasks {
struct ValueTask<T>
{
}
}
class Program
{
void M()
{
Func<int, ValueTask<int>> f = async x => await [|M2()|];
}
async ValueTask<int> M2()
{
return 0;
}
}"
,
@"using System;
using System.Threading.Tasks;
namespace System.Threading.Tasks {
struct ValueTask<T>
{
}
}
class Program
{
void M()
{
Func<int, ValueTask<int>> f = async x =>
{
ValueTask<int> {|Rename:valueTask|} = M2();
return await valueTask;
};
}
async ValueTask<int> M2()
{
return 0;
}
}"
);
}
}
...
...
src/Features/CSharp/Portable/IntroduceVariable/CSharpIntroduceVariableService_IntroduceLocal.cs
浏览文件 @
1de61162
...
...
@@ -125,8 +125,22 @@ internal partial class CSharpIntroduceVariableService
if
(
oldLambda
.
AsyncKeyword
!=
default
)
{
if
(
document
.
SemanticModel
.
Compilation
.
TaskType
().
Equals
(
delegateType
.
DelegateInvokeMethod
.
ReturnType
)
||
document
.
SemanticModel
.
Compilation
.
ValueTaskOfTType
().
Equals
(
delegateType
.
DelegateInvokeMethod
.
ReturnType
))
var
compilation
=
document
.
SemanticModel
.
Compilation
;
// Async lambdas with a Task or ValueTask return type don't need a return statement.
// e.g.:
// Func<int, Task> f = async x => await M2();
//
// After refactoring:
// Func<int, Task> f = async x =>
// {
// Task task = M2();
// await task;
// };
if
((
compilation
.
TaskType
()
!=
null
&&
compilation
.
TaskType
().
Equals
(
delegateType
.
DelegateInvokeMethod
.
ReturnType
))
||
(
compilation
.
ValueTaskOfType
()
!=
null
&&
compilation
.
ValueTaskOfType
().
Equals
(
delegateType
.
DelegateInvokeMethod
.
ReturnType
)))
{
return
false
;
}
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ICompilationExtensions.cs
浏览文件 @
1de61162
...
...
@@ -112,8 +112,12 @@ public static ImmutableArray<IAssemblySymbol> GetReferencedAssemblySymbols(this
public
static
INamedTypeSymbol
?
TaskOfTType
(
this
Compilation
compilation
)
=>
compilation
.
GetTypeByMetadataName
(
typeof
(
Task
<>).
FullName
!);
public
static
INamedTypeSymbol
?
ValueTaskOfType
(
this
Compilation
compilation
)
=>
compilation
.
GetTypeByMetadataName
(
"System.Threading.Tasks.ValueTask"
);
public
static
INamedTypeSymbol
?
ValueTaskOfTType
(
this
Compilation
compilation
)
=>
compilation
.
GetTypeByMetadataName
(
"System.Threading.Tasks.ValueTask`1"
);
public
static
INamedTypeSymbol
?
IEnumerableOfTType
(
this
Compilation
compilation
)
=>
compilation
.
GetTypeByMetadataName
(
typeof
(
IEnumerable
<>).
FullName
!);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录