Skip to content

Commit

Permalink
Merge pull request #49824 from jnm2/debuggerdisplay_static_class
Browse files Browse the repository at this point in the history
Stop offering to add DebuggerDisplay on static types
  • Loading branch information
CyrusNajmabadi authored Dec 7, 2020
2 parents abe0db9 + 2d900a6 commit 1afc0cf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ private string GetDebuggerDisplay()
}");
}

[Fact]
public async Task OfferedOnEmptyRecord()
{
await TestInRegularAndScriptAsync(@"
[||]record C;", @"
using System.Diagnostics;
[DebuggerDisplay(""{"" + nameof(GetDebuggerDisplay) + ""(),nq}"")]
record C
{
private string GetDebuggerDisplay()
{
return ToString();
}
}");
}

[Fact]
public async Task OfferedOnEmptyStruct()
{
Expand All @@ -57,6 +74,15 @@ private string GetDebuggerDisplay()
}");
}

[Fact]
public async Task NotOfferedOnStaticClass()
{
await TestMissingInRegularAndScriptAsync(@"
[||]static class Foo
{
}");
}

[Fact]
public async Task NotOfferedOnInterfaceWithToString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Structure Foo
End Structure")
End Function

<Fact>
Public Async Function NotOfferedOnModule() As Task
Await TestMissingInRegularAndScriptAsync("
[||]Module Foo
End Module")
End Function

<Fact>
Public Async Function NotOfferedOnInterfaceWithToString() As Task
Await TestMissingInRegularAndScriptAsync("
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ await GetRelevantTypeFromHeaderAsync(context).ConfigureAwait(false) ??

var typeSymbol = (INamedTypeSymbol)semanticModel.GetRequiredDeclaredSymbol(type, context.CancellationToken);

if (!IsClassOrStruct(typeSymbol))
if (typeSymbol.IsStatic || !IsClassOrStruct(typeSymbol))
return;

if (HasDebuggerDisplayAttribute(typeSymbol, compilation))
Expand Down

0 comments on commit 1afc0cf

Please sign in to comment.