Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
0de01e0f
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,发现更多精彩内容 >>
提交
0de01e0f
编写于
4月 24, 2017
作者:
C
Charles Stoner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PR feedback
上级
fd311df3
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
217 addition
and
10 deletion
+217
-10
src/Compilers/CSharp/Portable/Errors/LazyObsoleteDiagnosticInfo.cs
...lers/CSharp/Portable/Errors/LazyObsoleteDiagnosticInfo.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/ObsoleteAttributeHelpers.cs
...ilers/CSharp/Portable/Symbols/ObsoleteAttributeHelpers.cs
+3
-3
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Experimental.cs
...Sharp/Test/Emit/Attributes/AttributeTests_Experimental.cs
+37
-0
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs
...est/Emit/Attributes/AttributeTests_WellKnownAttributes.cs
+42
-1
src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
...ompilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
+3
-1
src/Compilers/VisualBasic/Portable/Errors/LazyObsoleteDiagnosticInfo.vb
...VisualBasic/Portable/Errors/LazyObsoleteDiagnosticInfo.vb
+1
-1
src/Compilers/VisualBasic/Portable/Symbols/ObsoleteAttributeHelpers.vb
.../VisualBasic/Portable/Symbols/ObsoleteAttributeHelpers.vb
+3
-3
src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_Experimental.vb
...Basic/Test/Emit/Attributes/AttributeTests_Experimental.vb
+53
-0
src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_ObsoleteAttribute.vb
.../Test/Emit/Attributes/AttributeTests_ObsoleteAttribute.vb
+74
-0
未找到文件。
src/Compilers/CSharp/Portable/Errors/LazyObsoleteDiagnosticInfo.cs
浏览文件 @
0de01e0f
...
...
@@ -31,7 +31,7 @@ internal override DiagnosticInfo GetResolvedInfo()
// from a different compilation's source. In that case, force completion of attributes.
_symbol
.
ForceCompleteObsoleteAttribute
();
var
kind
=
ObsoleteAttributeHelpers
.
GetObsoleteDiagnosticKind
(
_symbol
,
_containingSymbol
);
var
kind
=
ObsoleteAttributeHelpers
.
GetObsoleteDiagnosticKind
(
_symbol
,
_containingSymbol
,
forceComplete
:
true
);
Debug
.
Assert
(
kind
!=
ObsoleteDiagnosticKind
.
Lazy
);
Debug
.
Assert
(
kind
!=
ObsoleteDiagnosticKind
.
LazyPotentiallySuppressed
);
...
...
src/Compilers/CSharp/Portable/Symbols/ObsoleteAttributeHelpers.cs
浏览文件 @
0de01e0f
...
...
@@ -52,7 +52,7 @@ internal static ObsoleteAttributeData GetObsoleteDataFromMetadata(EntityHandle t
/// symbol's Obsoleteness is Unknown. False, if we are certain that no symbol in the parent
/// hierarchy is Obsolete.
/// </returns>
internal
static
ThreeState
GetObsoleteContextState
(
this
Symbol
symbol
,
bool
forceComplete
=
fals
e
)
private
static
ThreeState
GetObsoleteContextState
(
Symbol
symbol
,
bool
forceComplet
e
)
{
while
((
object
)
symbol
!=
null
)
{
...
...
@@ -88,7 +88,7 @@ internal static ThreeState GetObsoleteContextState(this Symbol symbol, bool forc
return
ThreeState
.
False
;
}
internal
static
ObsoleteDiagnosticKind
GetObsoleteDiagnosticKind
(
Symbol
symbol
,
Symbol
containingMember
)
internal
static
ObsoleteDiagnosticKind
GetObsoleteDiagnosticKind
(
Symbol
symbol
,
Symbol
containingMember
,
bool
forceComplete
=
false
)
{
switch
(
symbol
.
ObsoleteKind
)
{
...
...
@@ -104,7 +104,7 @@ internal static ObsoleteDiagnosticKind GetObsoleteDiagnosticKind(Symbol symbol,
return
ObsoleteDiagnosticKind
.
Lazy
;
}
switch
(
containingMember
.
GetObsoleteContextState
(
))
switch
(
GetObsoleteContextState
(
containingMember
,
forceComplete
))
{
case
ThreeState
.
False
:
return
ObsoleteDiagnosticKind
.
Diagnostic
;
...
...
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Experimental.cs
浏览文件 @
0de01e0f
...
...
@@ -561,5 +561,42 @@ static void Main()
// F(default(EP));
Diagnostic
(
ErrorCode
.
ERR_DeprecatedSymbolStr
,
"EP"
).
WithArguments
(
"EP"
,
"DP"
).
WithLocation
(
20
,
19
));
}
// Suppress diagnostics in unused import statements.
[
Fact
]
public
void
TestImportStatements
()
{
var
source
=
@"#pragma warning disable 219
#pragma warning disable 8019
using System;
using Windows.Foundation.Metadata;
using CA = C<A>;
using CB = C<B>;
using CC = C<C>;
using CD = C<D>;
[Obsolete] class A { }
[Obsolete] class B { }
[Experimental] class C { }
[Experimental] class D { }
class C<T> { }
class P
{
static void Main()
{
object o;
o = default(CB);
o = default(CD);
}
}"
;
var
comp
=
CreateCompilationWithMscorlibAndSystemCore
(
new
[]
{
Parse
(
ExperimentalAttributeSource
),
Parse
(
source
)
});
comp
.
VerifyDiagnostics
(
// (19,21): warning CS0612: 'B' is obsolete
// o = default(CB);
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbol
,
"CB"
).
WithArguments
(
"B"
).
WithLocation
(
19
,
21
),
// (20,21): warning CS8305: 'D' is for evaluation purposes only and is subject to change or removal in future updates.
// o = default(CD);
Diagnostic
(
ErrorCode
.
WRN_Experimental
,
"CD"
).
WithArguments
(
"D"
).
WithLocation
(
20
,
21
));
}
}
}
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_WellKnownAttributes.cs
浏览文件 @
0de01e0f
...
...
@@ -6507,6 +6507,45 @@ internal sealed class C1 : I1
Diagnostic
(
ErrorCode
.
HDN_UnusedUsingDirective
,
"using Y = A.B;"
));
}
[
Fact
]
public
void
TestObsoleteAndPropertyAccessors
()
{
var
source
=
@"using System;
[Obsolete] class A { }
[Obsolete] class B { }
class C
{
object P { get { return new A(); } }
[Obsolete] object Q { get { return new B(); } }
}"
;
var
comp
=
CreateCompilationWithMscorlibAndSystemCore
(
source
);
comp
.
VerifyDiagnostics
(
// (6,33): warning CS0612: 'A' is obsolete
// object P { get { return new A(); } }
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbol
,
"A"
).
WithArguments
(
"A"
).
WithLocation
(
6
,
33
));
}
[
Fact
]
public
void
TestObsoleteAndEventAccessors
()
{
var
source
=
@"using System;
[Obsolete] class A { }
[Obsolete] class B { }
class C
{
event EventHandler E { add { } remove { M(new A()); } }
[Obsolete] event EventHandler F { add { } remove { M(new B()); } }
static void M(object o) { }
}"
;
var
comp
=
CreateCompilationWithMscorlibAndSystemCore
(
source
);
comp
.
VerifyDiagnostics
(
// (6,51): warning CS0612: 'A' is obsolete
// event EventHandler E { add { } remove { M(new A()); } }
Diagnostic
(
ErrorCode
.
WRN_DeprecatedSymbol
,
"A"
).
WithArguments
(
"A"
).
WithLocation
(
6
,
51
));
}
[
Fact
]
[
WorkItem
(
531071
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531071"
)]
public
void
TestObsoleteTypeParameterInAlias
()
...
...
@@ -7702,7 +7741,9 @@ int P1
compilation2
.
VerifyDiagnostics
(
expected
);
}
// Report warning or error based on last attribute.
/// <summary>
/// Report warning or error based on last attribute.
/// </summary>
[
WorkItem
(
18755
,
"https://github.com/dotnet/roslyn/issues/18755"
)]
[
Fact
]
public
void
TestMultipleDeprecatedAttributes
()
...
...
src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
浏览文件 @
0de01e0f
...
...
@@ -46,7 +46,9 @@ public void Resources()
}
}
// ErrorCode should not have duplicates.
/// <summary>
/// ErrorCode should not have duplicates.
/// </summary>
[
Fact
]
public
void
NoDuplicates
()
{
...
...
src/Compilers/VisualBasic/Portable/Errors/LazyObsoleteDiagnosticInfo.vb
浏览文件 @
0de01e0f
...
...
@@ -25,7 +25,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' from a different compilation's source. In that case, force completion of attributes.
_symbol
.
ForceCompleteObsoleteAttribute
()
Dim
kind
=
ObsoleteAttributeHelpers
.
GetObsoleteDiagnosticKind
(
_containingSymbol
,
_symbol
)
Dim
kind
=
ObsoleteAttributeHelpers
.
GetObsoleteDiagnosticKind
(
_containingSymbol
,
_symbol
,
forceComplete
:
=
True
)
Debug
.
Assert
(
kind
<>
ObsoleteDiagnosticKind
.
Lazy
)
Debug
.
Assert
(
kind
<>
ObsoleteDiagnosticKind
.
LazyPotentiallySuppressed
)
...
...
src/Compilers/VisualBasic/Portable/Symbols/ObsoleteAttributeHelpers.vb
浏览文件 @
0de01e0f
...
...
@@ -44,7 +44,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
''' symbol's Obsoleteness is Unknown. False, if we are certain that no symbol in the parent
''' hierarchy is Obsolete.
''' </returns>
Friend
Shared
Function
GetObsoleteContextState
(
symbol
As
Symbol
,
Optional
forceComplete
As
Boolean
=
False
)
As
ThreeState
Private
Shared
Function
GetObsoleteContextState
(
symbol
As
Symbol
,
forceComplete
As
Boolean
)
As
ThreeState
While
symbol
IsNot
Nothing
' For property or event accessors, check the associated property or event instead.
If
symbol
.
IsAccessor
()
Then
...
...
@@ -66,7 +66,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return
ThreeState
.
False
End
Function
Friend
Shared
Function
GetObsoleteDiagnosticKind
(
context
As
Symbol
,
symbol
As
Symbol
)
As
ObsoleteDiagnosticKind
Friend
Shared
Function
GetObsoleteDiagnosticKind
(
context
As
Symbol
,
symbol
As
Symbol
,
Optional
forceComplete
As
Boolean
=
False
)
As
ObsoleteDiagnosticKind
Debug
.
Assert
(
context
IsNot
Nothing
)
Debug
.
Assert
(
symbol
IsNot
Nothing
)
...
...
@@ -83,7 +83,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return
ObsoleteDiagnosticKind
.
Lazy
End
Select
Select
Case
ObsoleteAttributeHelpers
.
GetObsoleteContextState
(
context
)
Select
Case
GetObsoleteContextState
(
context
,
forceComplete
)
Case
ThreeState
.
False
Return
ObsoleteDiagnosticKind
.
Diagnostic
Case
ThreeState
.
True
...
...
src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_Experimental.vb
浏览文件 @
0de01e0f
...
...
@@ -664,6 +664,59 @@ BC30668: 'CP' is obsolete: 'DP'.
</
errors
>
)
End
Sub
<
Fact
()
>
Public
Sub
TestImportStatements
()
Dim
ref0
=
CreateDeprecatedAndExperimentalAttributeReference
()
Dim
source
=
<
compilation
>
<
file
><
!
[
CDATA
[
Imports
System
Imports
Windows.Foundation.Metadata
Imports
CA
=
C
(
Of
A
)
Imports
CB
=
C
(
Of
B
)
Imports
CC
=
C
(
Of
C
)
Imports
CD
=
C
(
Of
D
)
<
Obsolete
>
Class
A
End
Class
<
Obsolete
>
Class
B
End
Class
<
Experimental
>
Class
C
End
Class
<
Experimental
>
Class
D
End
Class
Class
C
(
Of
T
)
End
Class
Class
P
Shared
Sub
Main
()
Dim
o
o
=
New
CB
()
o
=
New
CD
()
End
Sub
End
Class
]]
>
</
file
>
</
compilation
>
Dim
comp
=
CreateCompilationWithMscorlib
(
source
,
references
:
=
{
ref0
})
comp
.
AssertTheseDiagnostics
(
<
errors
><
!
[
CDATA
[
BC40008
:
'A' is obsolete.
Imports
CA
=
C
(
Of
A
)
~
BC40008
:
'B' is obsolete.
Imports
CB
=
C
(
Of
B
)
~
BC42380
:
'C' is for evaluation purposes only and is subject to change or removal in future updates.
Imports
CC
=
C
(
Of
C
)
~
BC42380
:
'D' is for evaluation purposes only and is subject to change or removal in future updates.
Imports
CD
=
C
(
Of
D
)
~
]]
></
errors
>
)
End
Sub
Private
Shared
Function
CreateDeprecatedAndExperimentalAttributeReference
()
As
MetadataReference
Dim
comp
=
CreateCompilationWithMscorlib
(
DeprecatedAndExperimentalAttributeSource
)
comp
.
AssertNoDiagnostics
()
...
...
src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests_ObsoleteAttribute.vb
浏览文件 @
0de01e0f
...
...
@@ -713,6 +713,80 @@ End Class
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
()
End
Sub
<
Fact
>
Public
Sub
TestObsoleteAndPropertyAccessors
()
Dim
source
=
<
compilation
>
<
file
><
!
[
CDATA
[
Imports
System
<
Obsolete
>
Class
A
End
Class
<
Obsolete
>
Class
B
End
Class
Class
C
ReadOnly
Property
P
As
Object
Get
Return
New
A
()
End
Get
End
Property
<
Obsolete
>
ReadOnly
Property
Q
As
Object
Get
Return
New
B
()
End
Get
End
Property
End
Class
]]
>
</
file
>
</
compilation
>
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
(
Diagnostic
(
ERRID
.
WRN_UseOfObsoleteSymbolNoMessage1
,
"A"
).
WithArguments
(
"A"
).
WithLocation
(
11
,
24
))
End
Sub
<
Fact
>
Public
Sub
TestObsoleteAndEventAccessors
()
Dim
source
=
<
compilation
>
<
file
><
!
[
CDATA
[
Imports
System
<
Obsolete
>
Class
A
End
Class
<
Obsolete
>
Class
B
End
Class
Class
C
Custom
Event
E
As
EventHandler
AddHandler
(
value
As
EventHandler
)
End
AddHandler
RemoveHandler
(
value
As
EventHandler
)
M
(
New
A
())
End
RemoveHandler
RaiseEvent
End
RaiseEvent
End
Event
<
Obsolete
>
Custom
Event
F
As
EventHandler
AddHandler
(
value
As
EventHandler
)
End
AddHandler
RemoveHandler
(
value
As
EventHandler
)
M
(
New
B
())
End
RemoveHandler
RaiseEvent
End
RaiseEvent
End
Event
Shared
Sub
M
(
o
As
Object
)
End
Sub
End
Class
]]
>
</
file
>
</
compilation
>
CreateCompilationWithMscorlib
(
source
).
VerifyDiagnostics
(
Diagnostic
(
ERRID
.
WRN_UseOfObsoleteSymbolNoMessage1
,
"A"
).
WithArguments
(
"A"
).
WithLocation
(
13
,
19
))
End
Sub
<
Fact
>
Public
Sub
TestObsoleteAttributeCycles_02
()
Dim
source
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录