Skip to content

Commit

Permalink
SealInternalTypes (CA1852): Don't warn for top-level type (#6278)
Browse files Browse the repository at this point in the history
* SealInternalTypes (CA1852): Don't warn for top-level type

* Fix build errors
  • Loading branch information
Youssef1313 authored Nov 23, 2022
1 parent 29bcd1c commit e439524
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ private static void OnCompilationStart(CompilationStartAnalysisContext context)
!type.IsStatic &&
!type.IsSealed &&
!type.IsExternallyVisible() &&
!type.HasAttribute(comImportAttributeType))
!type.HasAttribute(comImportAttributeType) &&
!type.IsTopLevelStatementsEntryPointType())
{
candidateTypes.Add(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Test.Utilities;
using Xunit;

using VerifyCS = Test.Utilities.CSharpCodeFixVerifier<
Expand Down Expand Up @@ -202,6 +203,20 @@ End Class
#endregion

#region No Diagnostic
[Fact, WorkItem(6141, "https://github.com/dotnet/roslyn-analyzers/issues/6141")]
public Task TopLevelStatementsProgram()
{
return new VerifyCS.Test()
{
TestState =
{
Sources = { "System.Console.WriteLine();" },
OutputKind = OutputKind.ConsoleApplication,
},
LanguageVersion = CodeAnalysis.CSharp.LanguageVersion.CSharp9,
}.RunAsync();
}

[Fact]
public Task PublicClassType_NoDiagnostic_CS()
{
Expand Down

0 comments on commit e439524

Please sign in to comment.