Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
9faaab10
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,发现更多精彩内容 >>
提交
9faaab10
编写于
1月 15, 2016
作者:
L
Llewellyn Pritchard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #7878 for interfaces
上级
71d47927
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
20 deletion
+70
-20
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
...rp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
+22
-20
src/Compilers/CSharp/Test/Symbol/Symbols/Source/BaseClassTests.cs
...ilers/CSharp/Test/Symbol/Symbols/Source/BaseClassTests.cs
+48
-0
未找到文件。
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
浏览文件 @
9faaab10
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
using
Roslyn.Utilities
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
Microsoft.CodeAnalysis.Collections
;
namespace
Microsoft.CodeAnalysis.CSharp.Symbols
namespace
Microsoft.CodeAnalysis.CSharp.Symbols
{
{
...
@@ -226,6 +227,7 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
...
@@ -226,6 +227,7 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
NamedTypeSymbol
baseType
=
null
;
NamedTypeSymbol
baseType
=
null
;
SourceLocation
baseTypeLocation
=
null
;
SourceLocation
baseTypeLocation
=
null
;
var
interfaceLocations
=
PooledDictionary
<
NamedTypeSymbol
,
SourceLocation
>.
GetInstance
();
foreach
(
var
decl
in
this
.
declaration
.
Declarations
)
foreach
(
var
decl
in
this
.
declaration
.
Declarations
)
{
{
...
@@ -258,34 +260,32 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
...
@@ -258,34 +260,32 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
}
}
}
}
int
n
=
baseInterfaces
.
Count
;
foreach
(
var
t
in
partInterfaces
)
foreach
(
var
t
in
partInterfaces
)
// this could probably be done more efficiently with a side hash table if it proves necessary
{
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
if
(!
interfaceLocations
.
ContainsKey
(
t
)
)
{
{
if
(
t
==
baseInterfaces
[
i
])
baseInterfaces
.
Add
(
t
);
{
interfaceLocations
.
Add
(
t
,
decl
.
NameLocation
);
goto
alreadyInInterfaceList
;
}
}
}
baseInterfaces
.
Add
(
t
);
alreadyInInterfaceList
:;
}
}
}
}
if
((
object
)
baseType
!=
null
&&
baseType
.
IsStatic
)
{
// '{1}': cannot derive from static class '{0}'
diagnostics
.
Add
(
ErrorCode
.
ERR_StaticBaseClass
,
baseTypeLocation
??
Locations
[
0
],
baseType
,
this
);
}
HashSet
<
DiagnosticInfo
>
useSiteDiagnostics
=
null
;
HashSet
<
DiagnosticInfo
>
useSiteDiagnostics
=
null
;
if
((
object
)
baseType
!=
null
&&
!
this
.
IsNoMoreVisibleThan
(
baseType
,
ref
useSiteDiagnostics
)
)
if
((
object
)
baseType
!=
null
)
{
{
// Inconsistent accessibility: base class '{1}' is less accessible than class '{0}'
Debug
.
Assert
(
baseTypeLocation
!=
null
);
diagnostics
.
Add
(
ErrorCode
.
ERR_BadVisBaseClass
,
baseTypeLocation
??
Locations
[
0
],
this
,
baseType
);
if
(
baseType
.
IsStatic
)
{
// '{1}': cannot derive from static class '{0}'
diagnostics
.
Add
(
ErrorCode
.
ERR_StaticBaseClass
,
baseTypeLocation
,
baseType
,
this
);
}
if
(!
this
.
IsNoMoreVisibleThan
(
baseType
,
ref
useSiteDiagnostics
))
{
// Inconsistent accessibility: base class '{1}' is less accessible than class '{0}'
diagnostics
.
Add
(
ErrorCode
.
ERR_BadVisBaseClass
,
baseTypeLocation
,
this
,
baseType
);
}
}
}
var
baseInterfacesRO
=
baseInterfaces
.
ToImmutableAndFree
();
var
baseInterfacesRO
=
baseInterfaces
.
ToImmutableAndFree
();
...
@@ -296,11 +296,13 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
...
@@ -296,11 +296,13 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
if
(!
i
.
IsAtLeastAsVisibleAs
(
this
,
ref
useSiteDiagnostics
))
if
(!
i
.
IsAtLeastAsVisibleAs
(
this
,
ref
useSiteDiagnostics
))
{
{
// Inconsistent accessibility: base interface '{1}' is less accessible than interface '{0}'
// Inconsistent accessibility: base interface '{1}' is less accessible than interface '{0}'
diagnostics
.
Add
(
ErrorCode
.
ERR_BadVisBaseInterface
,
Locations
[
0
],
this
,
i
);
diagnostics
.
Add
(
ErrorCode
.
ERR_BadVisBaseInterface
,
interfaceLocations
[
i
],
this
,
i
);
}
}
}
}
}
}
interfaceLocations
.
Free
();
diagnostics
.
Add
(
Locations
[
0
],
useSiteDiagnostics
);
diagnostics
.
Add
(
Locations
[
0
],
useSiteDiagnostics
);
return
new
Tuple
<
NamedTypeSymbol
,
ImmutableArray
<
NamedTypeSymbol
>>(
baseType
,
baseInterfacesRO
);
return
new
Tuple
<
NamedTypeSymbol
,
ImmutableArray
<
NamedTypeSymbol
>>(
baseType
,
baseInterfacesRO
);
...
...
src/Compilers/CSharp/Test/Symbol/Symbols/Source/BaseClassTests.cs
浏览文件 @
9faaab10
...
@@ -395,6 +395,54 @@ public partial class C1
...
@@ -395,6 +395,54 @@ public partial class C1
Diagnostic
(
ErrorCode
.
ERR_BadVisBaseClass
,
"C1"
).
WithArguments
(
"C1"
,
"NV"
).
WithLocation
(
10
,
15
));
Diagnostic
(
ErrorCode
.
ERR_BadVisBaseClass
,
"C1"
).
WithArguments
(
"C1"
,
"NV"
).
WithLocation
(
10
,
15
));
}
}
[
Fact
,
WorkItem
(
7878
,
"https://github.com/dotnet/roslyn/issues/7878"
)]
public
void
BadVisInterfacePartial
()
{
var
text
=
@"
interface IFoo
{
void Moo();
}
interface IBaz
{
void Noo();
}
interface IBam
{
void Zoo();
}
public partial interface IBar
{
}
partial interface IBar : IFoo, IBam
{
}
partial interface IBar : IBaz, IBaz
{
}
"
;
var
comp
=
CreateCompilationWithMscorlib
(
text
);
comp
.
VerifyDiagnostics
(
// (25,32): error CS0528: 'IBaz' is already listed in interface list
// partial interface IBar : IBaz, IBaz
Diagnostic
(
ErrorCode
.
ERR_DuplicateInterfaceInBaseList
,
"IBaz"
).
WithArguments
(
"IBaz"
).
WithLocation
(
25
,
32
),
// (21,19): error CS0061: Inconsistent accessibility: base interface 'IFoo' is less accessible than interface 'IBar'
// partial interface IBar : IFoo, IBam
Diagnostic
(
ErrorCode
.
ERR_BadVisBaseInterface
,
"IBar"
).
WithArguments
(
"IBar"
,
"IFoo"
).
WithLocation
(
21
,
19
),
// (21,19): error CS0061: Inconsistent accessibility: base interface 'IBam' is less accessible than interface 'IBar'
// partial interface IBar : IFoo, IBam
Diagnostic
(
ErrorCode
.
ERR_BadVisBaseInterface
,
"IBar"
).
WithArguments
(
"IBar"
,
"IBam"
).
WithLocation
(
21
,
19
),
// (25,19): error CS0061: Inconsistent accessibility: base interface 'IBaz' is less accessible than interface 'IBar'
// partial interface IBar : IBaz, IBaz
Diagnostic
(
ErrorCode
.
ERR_BadVisBaseInterface
,
"IBar"
).
WithArguments
(
"IBar"
,
"IBaz"
).
WithLocation
(
25
,
19
));
}
[
Fact
]
[
Fact
]
public
void
EricLiCase1
()
public
void
EricLiCase1
()
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录