Skip to content

Commit

Permalink
Fix accessibility detection
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorKrolic committed Apr 20, 2024
1 parent 37f0510 commit d4187e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 22 additions & 0 deletions tests/ArgumentParsing.Tests.Unit/OptionsTypeAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d4187e3

Please sign in to comment.