Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b4501d10
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,发现更多精彩内容 >>
提交
b4501d10
编写于
11月 08, 2018
作者:
Š
Šimon Koníček
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
For a yield return, inferring the type as the type argument of any generic type of arity 1
上级
b20f0bf1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
149 addition
and
19 deletion
+149
-19
src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateMethodTests.cs
...arpTest/Diagnostics/GenerateMethod/GenerateMethodTests.cs
+30
-0
src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs
...ures/CSharpTest/GenerateVariable/GenerateVariableTests.cs
+28
-0
src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
...itorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
+88
-9
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
...nguageServices/CSharpTypeInferenceService.TypeInferrer.cs
+3
-10
未找到文件。
src/EditorFeatures/CSharpTest/Diagnostics/GenerateMethod/GenerateMethodTests.cs
浏览文件 @
b4501d10
...
...
@@ -5134,6 +5134,36 @@ IEnumerable<int> Goo()
yield return Bar();
}
private int Bar()
{
throw new NotImplementedException();
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateMethod
)]
public
async
Task
TestWithYieldReturnInAsyncMethod
()
{
await
TestInRegularAndScriptAsync
(
@"using System.Collections.Generic;
class Program
{
async IAsyncEnumerable<int> Goo()
{
yield return [|Bar|]();
}
}"
,
@"using System;
using System.Collections.Generic;
class Program
{
async IAsyncEnumerable<int> Goo()
{
yield return Bar();
}
private int Bar()
{
throw new NotImplementedException();
...
...
src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs
浏览文件 @
b4501d10
...
...
@@ -4716,6 +4716,34 @@ IEnumerable<DayOfWeek> Goo()
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateVariable
)]
public
async
Task
TestWithYieldReturnInAsyncMethod
()
{
await
TestInRegularAndScriptAsync
(
@"using System;
using System.Collections.Generic;
class Program
{
async IAsyncEnumerable<DayOfWeek> Goo()
{
yield return [|abc|];
}
}"
,
@"using System;
using System.Collections.Generic;
class Program
{
private DayOfWeek abc;
async IAsyncEnumerable<DayOfWeek> Goo()
{
yield return abc;
}
}"
);
}
[
WorkItem
(
30235
,
"https://github.com/dotnet/roslyn/issues/30235"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateVariable
)]
public
async
Task
TestWithYieldReturnInLocalFunction
()
...
...
src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
浏览文件 @
b4501d10
...
...
@@ -1060,34 +1060,94 @@ public async Task TestExpressionBodiedAsyncVoidLocalFunction()
}
[
WorkItem
(
827897
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/827897"
)]
[
Theory
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
[
InlineData
(
"IEnumerable"
)]
[
InlineData
(
"IEnumerator"
)]
[
InlineData
(
"InvalidGenericType"
)]
public
async
Task
TestYieldReturnInMethod
(
string
returnTypeName
)
{
var
markup
=
$@"using System.Collections.Generic;
class C
{{
{
returnTypeName
}<
int
>
M
()
{{
yield
return
[|
abc
|]
}}
}}
"
;
await
TestAsync
(
markup
,
"global::System.Int32"
);
}
[
Theory
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
[
InlineData
(
"IAsyncEnumerable"
)]
[
InlineData
(
"IAsyncEnumerator"
)]
[
InlineData
(
"InvalidGenericType"
)]
public
async
Task
TestYieldReturnInAsyncMethod
(
string
returnTypeName
)
{
var
markup
=
$@"namespace System.Collections.Generic
{{
class
C
{{
interface
{
returnTypeName
}<
T
>
{{
}}
async
{
returnTypeName
}<
int
>
M
()
{{
yield
return
[|
abc
|]
}}
}}
}
}"
;
await
TestAsync
(
markup
,
"global::System.Int32"
);
}
[
Theory
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
[
InlineData
(
"int[]"
)]
[
InlineData
(
"InvalidNonGenericType"
)]
[
InlineData
(
"InvalidGenericType<int, int>"
)]
public
async
Task
TestYieldReturnInvalidTypeInMethod
(
string
returnType
)
{
var
markup
=
$@"class C
{{
{
returnType
}
M
()
{{
yield
return
[|
abc
|]
}}
}}
"
;
await
TestAsync
(
markup
,
"global::System.Object"
);
}
[
WorkItem
(
30235
,
"https://github.com/dotnet/roslyn/issues/30235"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
public
async
Task
TestYieldReturnIn
Method
()
public
async
Task
TestYieldReturnIn
LocalFunction
()
{
var
markup
=
@"using System.Collections.Generic;
class
Program
class
C
{
IEnumerable<int>
M()
void
M()
{
yield return [|abc|]
IEnumerable<int> F()
{
yield return [|abc|]
}
}
}"
;
await
TestAsync
(
markup
,
"global::System.Int32"
);
}
[
WorkItem
(
30235
,
"https://github.com/dotnet/roslyn/issues/30235"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
public
async
Task
TestYieldReturnIn
LocalFunction
()
public
async
Task
TestYieldReturnIn
PropertyGetter
()
{
var
markup
=
@"using System.Collections.Generic;
class
Program
class
C
{
void M()
IEnumerable<int> P
{
IEnumerable<int> F()
get
{
yield return [|abc|]
}
...
...
@@ -1096,6 +1156,25 @@ IEnumerable<int> F()
await
TestAsync
(
markup
,
"global::System.Int32"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
public
async
Task
TestYieldReturnInPropertySetter
()
{
var
markup
=
@"using System.Collections.Generic;
class C
{
IEnumerable<int> P
{
set
{
yield return [|abc|]
}
}
}"
;
await
TestAsync
(
markup
,
"global::System.Object"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
TypeInferenceService
)]
public
async
Task
TestYieldReturnAsGlobalStatement
()
{
...
...
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
浏览文件 @
b4501d10
...
...
@@ -1778,16 +1778,9 @@ private IEnumerable<TypeInferenceInfo> InferTypeInYieldStatement(YieldStatementS
var
memberType
=
GetMemberType
(
memberSymbol
,
out
_
);
if
(
memberType
is
INamedTypeSymbol
namedType
)
{
if
(
memberType
.
OriginalDefinition
.
SpecialType
==
SpecialType
.
System_Collections_Generic_IEnumerable_T
||
memberType
.
OriginalDefinition
.
SpecialType
==
SpecialType
.
System_Collections_Generic_IEnumerator_T
)
{
return
SpecializedCollections
.
SingletonEnumerable
(
new
TypeInferenceInfo
(
namedType
.
TypeArguments
[
0
]));
}
}
return
SpecializedCollections
.
EmptyEnumerable
<
TypeInferenceInfo
>();
return
memberType
is
INamedTypeSymbol
namedType
&&
namedType
.
TypeArguments
.
Length
==
1
?
SpecializedCollections
.
SingletonEnumerable
(
new
TypeInferenceInfo
(
namedType
.
TypeArguments
[
0
]))
:
SpecializedCollections
.
EmptyEnumerable
<
TypeInferenceInfo
>();
}
private
static
ITypeSymbol
GetMemberType
(
ISymbol
memberSymbol
,
out
bool
isAsync
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录