diff --git a/src/ArgumentParsing.Generators/ArgumentParserGenerator.Extract.cs b/src/ArgumentParsing.Generators/ArgumentParserGenerator.Extract.cs index ceecba8..0a5c40a 100644 --- a/src/ArgumentParsing.Generators/ArgumentParserGenerator.Extract.cs +++ b/src/ArgumentParsing.Generators/ArgumentParserGenerator.Extract.cs @@ -484,7 +484,7 @@ private static (OptionsInfo? OptionsInfo, OptionsHelpInfo? OptionsHelpInfo) Extr var qualifiedName = optionsType.ToDisplayString(s_qualifiedNameFormat); var optionsInfo = new OptionsInfo( qualifiedName, - optionsType.DeclaredAccessibility >= Accessibility.Internal, + optionsType.HasMinimalAccessibility(Accessibility.Internal), optionsBuilder.ToImmutable(), parametersBuilder.ToImmutable(), remainingParametersInfo, diff --git a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/OptionsTypeAnalyzer.cs b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/OptionsTypeAnalyzer.cs index 736a3dc..6458913 100644 --- a/src/ArgumentParsing.Generators/Diagnostics/Analyzers/OptionsTypeAnalyzer.cs +++ b/src/ArgumentParsing.Generators/Diagnostics/Analyzers/OptionsTypeAnalyzer.cs @@ -137,7 +137,7 @@ private static void AnalyzeOptionsType(SymbolAnalysisContext context, LanguageVe } } - if (optionsType.DeclaredAccessibility < Accessibility.Internal) + if (!optionsType.HasMinimalAccessibility(Accessibility.Internal)) { context.ReportDiagnostic( Diagnostic.Create( diff --git a/tests/ArgumentParsing.Tests.Unit/OptionsTypeAnalyzerTests.cs b/tests/ArgumentParsing.Tests.Unit/OptionsTypeAnalyzerTests.cs index f47c8ca..b0bb375 100644 --- a/tests/ArgumentParsing.Tests.Unit/OptionsTypeAnalyzerTests.cs +++ b/tests/ArgumentParsing.Tests.Unit/OptionsTypeAnalyzerTests.cs @@ -1529,6 +1529,28 @@ class C await VerifyAnalyzerAsync(source); } + [Theory] + [InlineData("")] + [InlineData("private")] + [InlineData("protected")] + public async Task TooLowOptionsTypeAccessibility_NestedType(string containingTypeAccessibility) + { + var source = $$""" + class Outer + { + {{containingTypeAccessibility}} class C + { + [OptionsType] + public class {|ARGP0032:Options|} + { + } + } + } + """; + + await VerifyAnalyzerAsync(source); + } + [Fact] public async Task NoShortAndLongName()