Skip to content

Commit

Permalink
SealInternalTypes (CA1852): Don't warn for top-level type
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 17, 2022
1 parent c5aa7bf commit 5f61625
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(string accessModifier)
{
await 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 5f61625

Please sign in to comment.