Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
280d6922
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,发现更多精彩内容 >>
提交
280d6922
编写于
6月 23, 2015
作者:
A
AlekseyTs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
C# SemanticModel.GetSymbolInfo - Properly handle explicit method group conversions.
Fixes #3096.
上级
7c1dd49d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
235 addition
and
1 deletion
+235
-1
src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs
...pilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs
+25
-0
src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs
src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs
+168
-0
src/Compilers/VisualBasic/Test/Semantic/Semantics/GetSemanticInfoTests.vb
...sualBasic/Test/Semantic/Semantics/GetSemanticInfoTests.vb
+41
-0
src/EditorFeatures/CSharpTest/CodeActions/InlineTemporary/InlineTemporaryTests.cs
...pTest/CodeActions/InlineTemporary/InlineTemporaryTests.cs
+1
-1
未找到文件。
src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs
浏览文件 @
280d6922
...
...
@@ -3649,6 +3649,31 @@ private static ImmutableArray<MethodSymbol> FilterOverriddenOrHiddenMethods(Immu
}
break
;
case
BoundKind
.
Conversion
:
// If we are looking for info on "M" in "(Action)M"
// we want to get the symbol that overload resolution chose for M, not the whole method group M.
var
conversion
=
(
BoundConversion
)
boundNodeForSyntacticParent
;
var
method
=
conversion
.
SymbolOpt
;
if
((
object
)
method
!=
null
)
{
Debug
.
Assert
(
conversion
.
ConversionKind
==
ConversionKind
.
MethodGroup
);
if
(
conversion
.
IsExtensionMethod
)
{
method
=
ReducedExtensionMethodSymbol
.
Create
(
method
);
}
symbols
=
ImmutableArray
.
Create
((
Symbol
)
method
);
resultKind
=
conversion
.
ResultKind
;
}
else
{
goto
default
;
}
break
;
case
BoundKind
.
DynamicInvocation
:
var
dynamicInvocation
=
(
BoundDynamicInvocation
)
boundNodeForSyntacticParent
;
symbols
=
dynamicInvocation
.
ApplicableMethods
.
Cast
<
MethodSymbol
,
Symbol
>();
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/BindingTests.cs
浏览文件 @
280d6922
...
...
@@ -2524,5 +2524,173 @@ static void Main()
CompileAndVerify
(
source
,
expectedOutput
:
"True"
);
}
[
Fact
,
WorkItem
(
3096
,
"https://github.com/dotnet/roslyn/issues/3096"
)]
public
void
CastToDelegate_01
()
{
var
sourceText
=
@"namespace NS
{
public static class A
{
public delegate void Action();
public static void M()
{
RunAction(A.B<string>.M0);
RunAction((Action)A.B<string>.M1);
}
private static void RunAction(Action action) { }
private class B<T>
{
public static void M0() { }
public static void M1() { }
}
}
}"
;
var
compilation
=
CreateCompilationWithMscorlib
(
sourceText
,
options
:
TestOptions
.
DebugDll
);
compilation
.
VerifyDiagnostics
();
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
var
identifierNameM0
=
tree
.
GetRoot
()
.
DescendantNodes
()
.
OfType
<
IdentifierNameSyntax
>()
.
First
(
x
=>
x
.
Parent
.
IsKind
(
SyntaxKind
.
SimpleMemberAccessExpression
)
&&
x
.
Identifier
.
ValueText
.
Equals
(
"M0"
));
Assert
.
Equal
(
"A.B<string>.M0"
,
identifierNameM0
.
Parent
.
ToString
());
var
m0Symbol
=
model
.
GetSymbolInfo
(
identifierNameM0
);
Assert
.
Equal
(
"void NS.A.B<System.String>.M0()"
,
m0Symbol
.
Symbol
.
ToTestDisplayString
());
Assert
.
Equal
(
CandidateReason
.
None
,
m0Symbol
.
CandidateReason
);
var
identifierNameM1
=
tree
.
GetRoot
()
.
DescendantNodes
()
.
OfType
<
IdentifierNameSyntax
>()
.
First
(
x
=>
x
.
Parent
.
IsKind
(
SyntaxKind
.
SimpleMemberAccessExpression
)
&&
x
.
Identifier
.
ValueText
.
Equals
(
"M1"
));
Assert
.
Equal
(
"A.B<string>.M1"
,
identifierNameM1
.
Parent
.
ToString
());
var
m1Symbol
=
model
.
GetSymbolInfo
(
identifierNameM1
);
Assert
.
Equal
(
"void NS.A.B<System.String>.M1()"
,
m1Symbol
.
Symbol
.
ToTestDisplayString
());
Assert
.
Equal
(
CandidateReason
.
None
,
m1Symbol
.
CandidateReason
);
}
[
Fact
,
WorkItem
(
3096
,
"https://github.com/dotnet/roslyn/issues/3096"
)]
public
void
CastToDelegate_02
()
{
var
sourceText
=
@"
class A
{
public delegate void MyDelegate<T>(T a);
public void Test()
{
UseMyDelegate((MyDelegate<int>)MyMethod);
UseMyDelegate((MyDelegate<long>)MyMethod);
UseMyDelegate((MyDelegate<float>)MyMethod);
UseMyDelegate((MyDelegate<double>)MyMethod);
}
private void UseMyDelegate<T>(MyDelegate<T> f) { }
private static void MyMethod(int a) { }
private static void MyMethod(long a) { }
private static void MyMethod(float a) { }
private static void MyMethod(double a) { }
}"
;
var
compilation
=
CreateCompilationWithMscorlib
(
sourceText
,
options
:
TestOptions
.
DebugDll
);
compilation
.
VerifyDiagnostics
();
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
var
identifiers
=
tree
.
GetRoot
()
.
DescendantNodes
()
.
OfType
<
IdentifierNameSyntax
>()
.
Where
(
x
=>
x
.
Identifier
.
ValueText
.
Equals
(
"MyMethod"
)).
ToArray
();
Assert
.
Equal
(
4
,
identifiers
.
Length
);
Assert
.
Equal
(
"(MyDelegate<int>)MyMethod"
,
identifiers
[
0
].
Parent
.
ToString
());
Assert
.
Equal
(
"void A.MyMethod(System.Int32 a)"
,
model
.
GetSymbolInfo
(
identifiers
[
0
]).
Symbol
.
ToTestDisplayString
());
Assert
.
Equal
(
"(MyDelegate<long>)MyMethod"
,
identifiers
[
1
].
Parent
.
ToString
());
Assert
.
Equal
(
"void A.MyMethod(System.Int64 a)"
,
model
.
GetSymbolInfo
(
identifiers
[
1
]).
Symbol
.
ToTestDisplayString
());
Assert
.
Equal
(
"(MyDelegate<float>)MyMethod"
,
identifiers
[
2
].
Parent
.
ToString
());
Assert
.
Equal
(
"void A.MyMethod(System.Single a)"
,
model
.
GetSymbolInfo
(
identifiers
[
2
]).
Symbol
.
ToTestDisplayString
());
Assert
.
Equal
(
"(MyDelegate<double>)MyMethod"
,
identifiers
[
3
].
Parent
.
ToString
());
Assert
.
Equal
(
"void A.MyMethod(System.Double a)"
,
model
.
GetSymbolInfo
(
identifiers
[
3
]).
Symbol
.
ToTestDisplayString
());
}
[
Fact
,
WorkItem
(
3096
,
"https://github.com/dotnet/roslyn/issues/3096"
)]
public
void
CastToDelegate_03
()
{
var
sourceText
=
@"namespace NS
{
public static class A
{
public delegate void Action();
public static void M()
{
var b = new A.B<string>();
RunAction(b.M0);
RunAction((Action)b.M1);
}
private static void RunAction(Action action) { }
public class B<T>
{
}
public static void M0<T>(this B<T> x) { }
public static void M1<T>(this B<T> x) { }
}
}"
;
var
compilation
=
CreateCompilationWithMscorlibAndSystemCore
(
sourceText
,
options
:
TestOptions
.
DebugDll
);
compilation
.
VerifyDiagnostics
();
var
tree
=
compilation
.
SyntaxTrees
.
Single
();
var
model
=
compilation
.
GetSemanticModel
(
tree
);
var
identifierNameM0
=
tree
.
GetRoot
()
.
DescendantNodes
()
.
OfType
<
IdentifierNameSyntax
>()
.
First
(
x
=>
x
.
Parent
.
IsKind
(
SyntaxKind
.
SimpleMemberAccessExpression
)
&&
x
.
Identifier
.
ValueText
.
Equals
(
"M0"
));
Assert
.
Equal
(
"b.M0"
,
identifierNameM0
.
Parent
.
ToString
());
var
m0Symbol
=
model
.
GetSymbolInfo
(
identifierNameM0
);
Assert
.
Equal
(
"void NS.A.B<System.String>.M0<System.String>()"
,
m0Symbol
.
Symbol
.
ToTestDisplayString
());
Assert
.
Equal
(
CandidateReason
.
None
,
m0Symbol
.
CandidateReason
);
var
identifierNameM1
=
tree
.
GetRoot
()
.
DescendantNodes
()
.
OfType
<
IdentifierNameSyntax
>()
.
First
(
x
=>
x
.
Parent
.
IsKind
(
SyntaxKind
.
SimpleMemberAccessExpression
)
&&
x
.
Identifier
.
ValueText
.
Equals
(
"M1"
));
Assert
.
Equal
(
"b.M1"
,
identifierNameM1
.
Parent
.
ToString
());
var
m1Symbol
=
model
.
GetSymbolInfo
(
identifierNameM1
);
Assert
.
Equal
(
"void NS.A.B<System.String>.M1<System.String>()"
,
m1Symbol
.
Symbol
.
ToTestDisplayString
());
Assert
.
Equal
(
CandidateReason
.
None
,
m1Symbol
.
CandidateReason
);
}
}
}
src/Compilers/VisualBasic/Test/Semantic/Semantics/GetSemanticInfoTests.vb
浏览文件 @
280d6922
...
...
@@ -1568,6 +1568,11 @@ Module Program
Dim
v5
=
F2
(
0
)
'BIND13:"F2"
x
=
C1
.
C
()
'BIND14:"C1.C"
d
=
CType
(
addressof
C1
.
B
,
Func
(
of
byte
))
'BIND15:"C1.B"
d
=
DirectCast
(
addressof
C1
.
B
,
Func
(
of
byte
))
'BIND16:"C1.B"
d
=
TryCast
(
addressof
C1
.
B
,
Func
(
of
byte
))
'BIND17:"C1.B"
End
Sub
Function
F
()
As
Func
(
Of
Integer
,
Integer
)
...
...
@@ -1589,6 +1594,21 @@ End Module
</
file
>
</
compilation
>
)
compilation
.
AssertTheseDiagnostics
(
<
expected
>
BC35000
:
Requested
operation
is
not
available
because
the
runtime
library
function
'Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute..ctor' is not defined.
Module
Program
~~~~~~~
BC30454
:
Expression
is
not
a
method
.
C1
.
A
'BIND:"C1.A"
~~~~
BC30545
:
Property
access
must
assign
to
the
property
or
use
its
value
.
C1
.
C
'BIND2:"C1.C"
~~~~
BC42104
:
Variable
'o' is used before it has been assigned a value. A null reference exception could result at runtime.
Dim
c
=
o
.
ToString
(
0
)
'BIND7:"o.ToString"
~
</
expected
>
)
Dim
model
=
GetSemanticModel
(
compilation
,
"a.vb"
)
Dim
expressionSyntax
=
CompilationUtils
.
FindBindingText
(
Of
MemberAccessExpressionSyntax
)(
compilation
,
"a.vb"
,
0
)
Dim
symbolInfo
=
model
.
GetSymbolInfo
(
expressionSyntax
)
...
...
@@ -1691,6 +1711,27 @@ End Module
Assert
.
Equal
(
"C"
,
symbolInfo
.
Symbol
.
Name
)
typeInfo
=
model
.
GetTypeInfo
(
expressionSyntax
)
Assert
.
Null
(
typeInfo
.
Type
)
expressionSyntax
=
CompilationUtils
.
FindBindingText
(
Of
MemberAccessExpressionSyntax
)(
compilation
,
"a.vb"
,
15
)
symbolInfo
=
model
.
GetSymbolInfo
(
expressionSyntax
)
Assert
.
Equal
(
"Function C1.B() As System.Byte"
,
symbolInfo
.
Symbol
.
ToTestDisplayString
())
Assert
.
Equal
(
CandidateReason
.
None
,
symbolInfo
.
CandidateReason
)
typeInfo
=
model
.
GetTypeInfo
(
expressionSyntax
)
Assert
.
Null
(
typeInfo
.
Type
)
expressionSyntax
=
CompilationUtils
.
FindBindingText
(
Of
MemberAccessExpressionSyntax
)(
compilation
,
"a.vb"
,
16
)
symbolInfo
=
model
.
GetSymbolInfo
(
expressionSyntax
)
Assert
.
Equal
(
"Function C1.B() As System.Byte"
,
symbolInfo
.
Symbol
.
ToTestDisplayString
())
Assert
.
Equal
(
CandidateReason
.
None
,
symbolInfo
.
CandidateReason
)
typeInfo
=
model
.
GetTypeInfo
(
expressionSyntax
)
Assert
.
Null
(
typeInfo
.
Type
)
expressionSyntax
=
CompilationUtils
.
FindBindingText
(
Of
MemberAccessExpressionSyntax
)(
compilation
,
"a.vb"
,
17
)
symbolInfo
=
model
.
GetSymbolInfo
(
expressionSyntax
)
Assert
.
Equal
(
"Function C1.B() As System.Byte"
,
symbolInfo
.
Symbol
.
ToTestDisplayString
())
Assert
.
Equal
(
CandidateReason
.
None
,
symbolInfo
.
CandidateReason
)
typeInfo
=
model
.
GetTypeInfo
(
expressionSyntax
)
Assert
.
Null
(
typeInfo
.
Type
)
End
Sub
<
WorkItem
(
543572
,
"DevDiv"
)
>
...
...
src/EditorFeatures/CSharpTest/CodeActions/InlineTemporary/InlineTemporaryTests.cs
浏览文件 @
280d6922
...
...
@@ -2054,7 +2054,7 @@ class C
static void Main()
{
Action<string> g = null;
var h =
(Foo<string>)
+ g;
var h =
Foo
+ g;
}
static void Foo<T>(T y) { }
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录