Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d0b7cd4d
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,发现更多精彩内容 >>
未验证
提交
d0b7cd4d
编写于
8月 06, 2020
作者:
C
Charles Stoner
提交者:
GitHub
8月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add event test (#46574)
上级
6291c0fc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
74 addition
and
0 deletion
+74
-0
src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs
...CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs
+74
-0
未找到文件。
src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs
浏览文件 @
d0b7cd4d
...
...
@@ -11293,11 +11293,23 @@ static void M(Derived<B> d, A a)
var
comp
=
CreateCompilation
(
new
[]
{
source0
,
source1
,
source2
});
comp
.
VerifyEmitDiagnostics
();
verify
(
comp
,
comp
.
SyntaxTrees
[
2
]);
var
ref0
=
CreateCompilation
(
source0
).
EmitToImageReference
();
var
ref1
=
CreateCompilation
(
source1
,
references
:
new
[]
{
ref0
}).
EmitToImageReference
();
comp
=
CreateCompilation
(
source2
,
references
:
new
[]
{
ref0
,
ref1
});
comp
.
VerifyEmitDiagnostics
();
verify
(
comp
,
comp
.
SyntaxTrees
[
0
]);
static
void
verify
(
CSharpCompilation
comp
,
SyntaxTree
tree
)
{
var
model
=
comp
.
GetSemanticModel
(
tree
);
var
expr
=
tree
.
GetRoot
().
DescendantNodes
().
OfType
<
InvocationExpressionSyntax
>().
Single
();
var
symbol
=
model
.
GetSymbolInfo
(
expr
).
Symbol
.
GetSymbol
<
MethodSymbol
>();
Assert
.
Equal
(
"B Derived<B>.F(A key)"
,
symbol
.
ToTestDisplayString
());
symbol
=
symbol
.
GetLeastOverriddenMethod
(
accessingTypeOpt
:
null
);
Assert
.
Equal
(
"B Base<A, B>.F(A key)"
,
symbol
.
ToTestDisplayString
());
}
}
[
Fact
]
...
...
@@ -11330,11 +11342,73 @@ static void M(Derived<B> d, A a)
var
comp
=
CreateCompilation
(
new
[]
{
source0
,
source1
,
source2
});
comp
.
VerifyEmitDiagnostics
();
verify
(
comp
,
comp
.
SyntaxTrees
[
2
]);
var
ref0
=
CreateCompilation
(
source0
).
EmitToImageReference
();
var
ref1
=
CreateCompilation
(
source1
,
references
:
new
[]
{
ref0
}).
EmitToImageReference
();
comp
=
CreateCompilation
(
source2
,
references
:
new
[]
{
ref0
,
ref1
});
comp
.
VerifyEmitDiagnostics
();
verify
(
comp
,
comp
.
SyntaxTrees
[
0
]);
static
void
verify
(
CSharpCompilation
comp
,
SyntaxTree
tree
)
{
var
model
=
comp
.
GetSemanticModel
(
tree
);
var
expr
=
tree
.
GetRoot
().
DescendantNodes
().
OfType
<
ElementAccessExpressionSyntax
>().
Single
();
var
symbol
=
model
.
GetSymbolInfo
(
expr
).
Symbol
.
GetSymbol
<
PropertySymbol
>();
Assert
.
Equal
(
"B Derived<B>.this[A key] { get; }"
,
symbol
.
ToTestDisplayString
());
symbol
=
symbol
.
GetLeastOverriddenProperty
(
accessingTypeOpt
:
null
);
Assert
.
Equal
(
"B Base<A, B>.this[A key] { get; }"
,
symbol
.
ToTestDisplayString
());
}
}
[
Fact
]
[
WorkItem
(
46549
,
"https://github.com/dotnet/roslyn/issues/46549"
)]
public
void
GenericTypeOverriddenEvent
()
{
var
source0
=
@"public delegate TValue D<TKey, TValue>(TKey key);
public abstract class Base<TKey, TValue>
where TKey : class
where TValue : class
{
public abstract event D<TKey, TValue> E;
}"
;
var
source1
=
@"public class A { }
public class Derived<TValue> : Base<A, TValue>
where TValue : class
{
public override event D<A, TValue> E { add { } remove { } }
}"
;
var
source2
=
@"class B { }
class Program
{
static void M(Derived<B> d, A a)
{
d.E += (A a) => default(B);
}
}"
;
var
comp
=
CreateCompilation
(
new
[]
{
source0
,
source1
,
source2
});
comp
.
VerifyEmitDiagnostics
();
verify
(
comp
,
comp
.
SyntaxTrees
[
2
]);
var
ref0
=
CreateCompilation
(
source0
).
EmitToImageReference
();
var
ref1
=
CreateCompilation
(
source1
,
references
:
new
[]
{
ref0
}).
EmitToImageReference
();
comp
=
CreateCompilation
(
source2
,
references
:
new
[]
{
ref0
,
ref1
});
comp
.
VerifyEmitDiagnostics
();
verify
(
comp
,
comp
.
SyntaxTrees
[
0
]);
static
void
verify
(
CSharpCompilation
comp
,
SyntaxTree
tree
)
{
var
model
=
comp
.
GetSemanticModel
(
tree
);
var
expr
=
tree
.
GetRoot
().
DescendantNodes
().
OfType
<
MemberAccessExpressionSyntax
>().
Single
();
var
symbol
=
model
.
GetSymbolInfo
(
expr
).
Symbol
.
GetSymbol
<
EventSymbol
>();
Assert
.
Equal
(
"event D<A, B> Derived<B>.E"
,
symbol
.
ToTestDisplayString
());
symbol
=
symbol
.
GetLeastOverriddenEvent
(
accessingTypeOpt
:
null
);
Assert
.
Equal
(
"event D<A, B> Base<A, B>.E"
,
symbol
.
ToTestDisplayString
());
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录