Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6590dd95
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,发现更多精彩内容 >>
提交
6590dd95
编写于
12月 12, 2017
作者:
J
Julien Couvreur
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix semantic model on type parameters of local functions
上级
919b606f
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
146 addition
and
20 deletion
+146
-20
src/Compilers/CSharp/Portable/Compilation/SyntaxTreeSemanticModel.cs
...rs/CSharp/Portable/Compilation/SyntaxTreeSemanticModel.cs
+20
-20
src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
...lers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
+38
-0
src/EditorFeatures/Test2/FindReferences/FindReferencesTests.TypeParameterTypeSymbol.vb
...References/FindReferencesTests.TypeParameterTypeSymbol.vb
+88
-0
未找到文件。
src/Compilers/CSharp/Portable/Compilation/SyntaxTreeSemanticModel.cs
浏览文件 @
6590dd95
...
...
@@ -1987,29 +1987,29 @@ public override ITypeParameterSymbol GetDeclaredSymbol(TypeParameterSyntax typeP
throw
new
ArgumentException
(
"typeParameter not within tree"
);
}
var
typeParamList
=
typeParameter
.
Parent
as
TypeParameterListSyntax
;
if
(
typeParamList
!=
null
)
if
(
typeParameter
.
Parent
is
TypeParameterListSyntax
typeParamList
)
{
var
memberDecl
=
typeParamList
.
Parent
as
MemberDeclarationSyntax
;
if
(
memberDecl
!=
null
)
{
var
symbol
=
GetDeclaredSymbol
(
memberDecl
,
cancellationToken
);
if
((
object
)
symbol
!=
null
)
{
var
typeSymbol
=
symbol
as
NamedTypeSymbol
;
if
((
object
)
typeSymbol
!=
null
)
ISymbol
parameterizedSymbol
=
null
;
switch
(
typeParamList
.
Parent
)
{
return
this
.
GetTypeParameterSymbol
(
typeSymbol
.
TypeParameters
,
typeParameter
);
case
MemberDeclarationSyntax
memberDecl
:
parameterizedSymbol
=
GetDeclaredSymbol
(
memberDecl
,
cancellationToken
);
break
;
case
LocalFunctionStatementSyntax
localDecl
:
parameterizedSymbol
=
GetDeclaredSymbol
(
localDecl
,
cancellationToken
);
break
;
}
var
methodSymbol
=
symbol
as
MethodSymbol
;
if
((
object
)
methodSymbol
!=
null
)
switch
(
parameterizedSymbol
)
{
return
this
.
GetTypeParameterSymbol
(
methodSymbol
.
TypeParameters
,
typeParameter
)
??
((
object
)
methodSymbol
.
PartialDefinitionPart
==
null
?
null
:
this
.
GetTypeParameterSymbol
(
methodSymbol
.
PartialDefinitionPart
.
TypeParameters
,
typeParameter
));
}
}
case
NamedTypeSymbol
typeSymbol
:
return
this
.
GetTypeParameterSymbol
(
typeSymbol
.
TypeParameters
,
typeParameter
);
case
MethodSymbol
methodSymbol
:
return
this
.
GetTypeParameterSymbol
(
methodSymbol
.
TypeParameters
,
typeParameter
)
??
((
object
)
methodSymbol
.
PartialDefinitionPart
==
null
?
null
:
this
.
GetTypeParameterSymbol
(
methodSymbol
.
PartialDefinitionPart
.
TypeParameters
,
typeParameter
));
}
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/LocalFunctionTests.cs
浏览文件 @
6590dd95
...
...
@@ -3331,5 +3331,43 @@ static void M()
Diagnostic
(
ErrorCode
.
ERR_DynamicLocalFunctionTypeParameter
,
"L5(1, 3, val)"
).
WithArguments
(
"L5"
).
WithLocation
(
26
,
9
)
);
}
[
Fact
]
[
WorkItem
(
23699
,
"https://github.com/dotnet/roslyn/issues/23699"
)]
public
void
GetDeclaredSymbolOnTypeParameter
()
{
var
src
=
@"
class C<T>
{
void M<U>()
{
void LocalFunction<T, U, V>(T p1, U p2, V p3)
{
}
}
}
"
;
var
comp
=
CreateStandardCompilation
(
src
);
var
tree
=
comp
.
SyntaxTrees
.
Single
();
var
model
=
comp
.
GetSemanticModel
(
tree
);
var
localDecl
=
(
LocalFunctionStatementSyntax
)
tree
.
FindNodeOrTokenByKind
(
SyntaxKind
.
LocalFunctionStatement
).
AsNode
();
var
typeParameters
=
localDecl
.
TypeParameterList
.
Parameters
;
var
parameters
=
localDecl
.
ParameterList
.
Parameters
;
verifyTypeParameterAndParameter
(
typeParameters
[
0
],
parameters
[
0
],
"T"
);
verifyTypeParameterAndParameter
(
typeParameters
[
1
],
parameters
[
1
],
"U"
);
verifyTypeParameterAndParameter
(
typeParameters
[
2
],
parameters
[
2
],
"V"
);
void
verifyTypeParameterAndParameter
(
TypeParameterSyntax
typeParameter
,
ParameterSyntax
parameter
,
string
expected
)
{
var
symbol
=
model
.
GetDeclaredSymbol
(
typeParameter
);
Assert
.
Equal
(
expected
,
symbol
.
ToTestDisplayString
());
var
parameterSymbol
=
model
.
GetDeclaredSymbol
(
parameter
);
Assert
.
Equal
(
expected
,
parameterSymbol
.
Type
.
ToTestDisplayString
());
Assert
.
True
(
symbol
==
parameterSymbol
.
Type
);
}
}
}
}
src/EditorFeatures/Test2/FindReferences/FindReferencesTests.TypeParameterTypeSymbol.vb
浏览文件 @
6590dd95
...
...
@@ -25,6 +25,94 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.FindReferences
Await
TestAPIAndFeature
(
input
)
End
Function
<
WorkItem
(
23699
,
"https://github.com/dotnet/roslyn/issues/23699"
)
>
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
FindReferences
)
>
Public
Async
Function
TestCSharp_LocalFunctionTypeParameter
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
><
!
[
CDATA
[
class
C
{
void
M
()
{
void
local
<
{
|
Definition
:
TPar
$$
am
|
}
>
(
[|
TParam
|]
parameter
)
{
}
}
}
]]
></
Document
>
</
Project
>
</
Workspace
>
Await
TestAPIAndFeature
(
input
)
End
Function
<
WorkItem
(
23699
,
"https://github.com/dotnet/roslyn/issues/23699"
)
>
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
FindReferences
)
>
Public
Async
Function
TestCSharp_LocalFunctionTypeParameter2
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
><
!
[
CDATA
[
class
C
{
void
M
()
{
void
local
<
{
|
Definition
:
TParam
|
}
>
(
[|
TPa
$$
ram
|]
parameter
)
{
}
}
}
]]
></
Document
>
</
Project
>
</
Workspace
>
Await
TestAPIAndFeature
(
input
)
End
Function
<
WorkItem
(
23699
,
"https://github.com/dotnet/roslyn/issues/23699"
)
>
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
FindReferences
)
>
Public
Async
Function
TestCSharp_LocalFunctionTypeParameter3
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
><
!
[
CDATA
[
class
C
{
void
M
<
{
|
Definition
:
TParam
|
}
>
()
{
void
local
(
[|
TPa
$$
ram
|]
parameter
)
{
}
}
}
]]
></
Document
>
</
Project
>
</
Workspace
>
Await
TestAPIAndFeature
(
input
)
End
Function
<
WorkItem
(
23699
,
"https://github.com/dotnet/roslyn/issues/23699"
)
>
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
FindReferences
)
>
Public
Async
Function
TestCSharp_LocalFunctionTypeParameter4
()
As
Task
Dim
input
=
<
Workspace
>
<
Project
Language
=
"C#"
CommonReferences
=
"true"
>
<
Document
><
!
[
CDATA
[
class
C
{
void
M
<
{
|
Definition
:
TPa
$$
ram
|
}
>
()
{
void
local
(
[|
TParam
|]
parameter
)
{
}
}
}
]]
></
Document
>
</
Project
>
</
Workspace
>
Await
TestAPIAndFeature
(
input
)
End
Function
<
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
FindReferences
)
>
Public
Async
Function
TestTypeParameter2
()
As
Task
Dim
input
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录