Skip to content

Commit

Permalink
Add support for `System.Diagnostics.CodeAnalysis.ExperimentalAttribut…
Browse files Browse the repository at this point in the history
…e` (#68702)
  • Loading branch information
jcouv authored Jul 6, 2023
1 parent c022624 commit cd51ca0
Show file tree
Hide file tree
Showing 14 changed files with 1,361 additions and 17 deletions.
16 changes: 14 additions & 2 deletions src/Compilers/CSharp/Portable/Symbols/ObsoleteAttributeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ internal static ObsoleteDiagnosticKind GetObsoleteDiagnosticKind(Symbol symbol,
{
case ObsoleteAttributeKind.None:
return ObsoleteDiagnosticKind.NotObsolete;
case ObsoleteAttributeKind.WindowsExperimental:
case ObsoleteAttributeKind.Experimental:
return ObsoleteDiagnosticKind.Diagnostic;
case ObsoleteAttributeKind.Uninitialized:
Expand Down Expand Up @@ -154,12 +155,23 @@ static DiagnosticInfo createObsoleteDiagnostic(Symbol symbol, BinderFlags locati
return null;
}

if (data.Kind == ObsoleteAttributeKind.Experimental)
if (data.Kind == ObsoleteAttributeKind.WindowsExperimental)
{
Debug.Assert(data.Message == null);
Debug.Assert(!data.IsError);
// Provide an explicit format for fully-qualified type names.
return new CSDiagnosticInfo(ErrorCode.WRN_Experimental, new FormattedSymbol(symbol, SymbolDisplayFormat.CSharpErrorMessageFormat));
return new CSDiagnosticInfo(ErrorCode.WRN_Experimental,
new FormattedSymbol(symbol, SymbolDisplayFormat.CSharpErrorMessageFormat));
}

if (data.Kind == ObsoleteAttributeKind.Experimental)
{
Debug.Assert(data.Message is null);
Debug.Assert(!data.IsError);

// Provide an explicit format for fully-qualified type names.
return new CustomObsoleteDiagnosticInfo(MessageProvider.Instance, (int)ErrorCode.WRN_Experimental, data,
new FormattedSymbol(symbol, SymbolDisplayFormat.CSharpErrorMessageFormat));
}

// Issue a specialized diagnostic for add methods of collection initializers
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Symbols/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ internal ThreeState ObsoleteState
switch (ObsoleteKind)
{
case ObsoleteAttributeKind.None:
case ObsoleteAttributeKind.WindowsExperimental:
case ObsoleteAttributeKind.Experimental:
return ThreeState.False;
case ObsoleteAttributeKind.Uninitialized:
Expand Down
4 changes: 4 additions & 0 deletions src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ internal static bool EarlyDecodeDeprecatedOrExperimentalOrObsoleteAttribute(
{
kind = ObsoleteAttributeKind.Deprecated;
}
else if (CSharpAttributeData.IsTargetEarlyAttribute(type, syntax, AttributeDescription.WindowsExperimentalAttribute))
{
kind = ObsoleteAttributeKind.WindowsExperimental;
}
else if (CSharpAttributeData.IsTargetEarlyAttribute(type, syntax, AttributeDescription.ExperimentalAttribute))
{
kind = ObsoleteAttributeKind.Experimental;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public class AttributeTests_Experimental : CSharpTestBase
public class AttributeTests_WindowsExperimental : CSharpTestBase
{
private const string DeprecatedAttributeSource =
@"using System;
Expand Down
Loading

0 comments on commit cd51ca0

Please sign in to comment.