提交 0de01e0f 编写于 作者: C Charles Stoner

PR feedback

上级 fd311df3
......@@ -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);
......
......@@ -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 = false)
private static ThreeState GetObsoleteContextState(Symbol symbol, bool forceComplete)
{
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;
......
......@@ -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));
}
}
}
......@@ -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()
......
......@@ -46,7 +46,9 @@ public void Resources()
}
}
// ErrorCode should not have duplicates.
/// <summary>
/// ErrorCode should not have duplicates.
/// </summary>
[Fact]
public void NoDuplicates()
{
......
......@@ -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)
......
......@@ -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
......
......@@ -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()
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册