Skip to content

Commit

Permalink
Fix visibility of macros
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Sep 6, 2022
1 parent 18aed91 commit 53e2b85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Microsoft.Windows.CsWin32/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,7 @@ internal void RequestMacro(MethodDeclarationSyntax macro)
{
this.volatileCode.GenerateMacro(macro.Identifier.ValueText, delegate
{
this.volatileCode.AddMacro(macro.Identifier.ValueText, macro);
this.volatileCode.AddMacro(macro.Identifier.ValueText, (MethodDeclarationSyntax)ElevateVisibility(macro));

// Generate any additional types that this macro relies on.
foreach (QualifiedNameSyntax identifier in macro.DescendantNodes().OfType<QualifiedNameSyntax>())
Expand Down
12 changes: 12 additions & 0 deletions test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,18 @@ public void HandleStructsHaveStaticNullMember(string handleName)
this.AssertGeneratedMember(handleName, "Null", $"internal static {handleName} Null => default;");
}

[Theory, PairwiseData]
public void MacroAPIsGenerateWithAppropriateVisibility(bool publicVisibility)
{
this.generator = this.CreateGenerator(DefaultTestGeneratorOptions with { Public = publicVisibility });
Assert.True(this.generator.TryGenerate("HRESULT_FROM_WIN32", CancellationToken.None));
this.CollectGeneratedCode(this.generator);
this.AssertNoDiagnostics();
var method = Assert.Single(this.FindGeneratedMethod("HRESULT_FROM_WIN32"));

Assert.True(method.Modifiers.Any(publicVisibility ? SyntaxKind.PublicKeyword : SyntaxKind.InternalKeyword));
}

[Theory]
[InlineData("HRESULT_FROM_WIN32")]
public void MacroAPIsGenerate(string macro)
Expand Down

0 comments on commit 53e2b85

Please sign in to comment.