Skip to content

Commit

Permalink
Fix source-generator bug with nonpublic constructors (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin authored Mar 14, 2024
1 parent aa09f16 commit 0a613e9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/NodeApi.Generator/ModuleGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ private void ExportType(
LambdaExpression adapter;
ConstructorInfo[] constructors = type.GetMembers()
.OfType<IMethodSymbol>()
.Where((m) => m.MethodKind == MethodKind.Constructor)
.Where((m) => m.MethodKind == MethodKind.Constructor &&
m.DeclaredAccessibility == Accessibility.Public)
.Select((c) => c.AsConstructorInfo())
.ToArray();
if (constructors.Length == 1)
Expand All @@ -493,7 +494,9 @@ private void ExportType(
_callbackAdapters.Add(adapter.Name!, adapter);
}
else if (type.GetMembers().OfType<IMethodSymbol>().Any((m) =>
m.MethodKind == MethodKind.Constructor && m.Parameters.Length == 0))
m.MethodKind == MethodKind.Constructor &&
m.DeclaredAccessibility == Accessibility.Public &&
m.Parameters.Length == 0))
{
s += $"\t() => new {ns}.{type.Name}())";
}
Expand Down Expand Up @@ -741,7 +744,8 @@ public static string GetExportName(ISymbol symbol)
private bool IsConstructorCallbackAdapterRequired(ITypeSymbol type)
{
IMethodSymbol[] constructors = type.GetMembers().OfType<IMethodSymbol>()
.Where((m) => m.MethodKind == MethodKind.Constructor)
.Where((m) => m.MethodKind == MethodKind.Constructor &&
m.DeclaredAccessibility == Accessibility.Public)
.ToArray();
if (constructors.Length > 1)
{
Expand Down

0 comments on commit 0a613e9

Please sign in to comment.