Skip to content

Commit

Permalink
Generate more friendly overloads on net35
Browse files Browse the repository at this point in the history
We were excluding certain friendly overloads on net35 on the basis that `Span<T>` isn't supported there, even when the friendly overloads didn't require that type. With this change, we have fine-tuned the exclusion to only restrict the friendly overloads' parameter changes that would require `Span<T>`.
This fixes #888.
  • Loading branch information
AArnott committed Mar 20, 2023
1 parent 27f494b commit 62df282
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.Windows.CsWin32/Generator.FriendlyOverloads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ private IEnumerable<MethodDeclarationSyntax> DeclareFriendlyOverloads(MethodDefi
}
else if ((externParam.Type is PointerTypeSyntax { ElementType: TypeSyntax ptrElementType }
&& !IsVoid(ptrElementType)
&& !this.IsInterface(parameterTypeInfo)
&& this.canUseSpan) ||
&& !this.IsInterface(parameterTypeInfo)) ||
externParam.Type is ArrayTypeSyntax)
{
TypeSyntax elementType = externParam.Type is PointerTypeSyntax ptr ? ptr.ElementType
Expand Down Expand Up @@ -249,6 +248,7 @@ private IEnumerable<MethodDeclarationSyntax> DeclareFriendlyOverloads(MethodDefi
// It is possible that sizeParamIndex points to a parameter that is not on the extern method
// when the parameter is the last one and was moved to a return value.
if (sizeParamIndex.HasValue
&& this.canUseSpan
&& externMethodDeclaration.ParameterList.Parameters.Count > sizeParamIndex.Value
&& !(externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Type is PointerTypeSyntax)
&& !(externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Modifiers.Any(SyntaxKind.OutKeyword) || externMethodDeclaration.ParameterList.Parameters[sizeParamIndex.Value].Modifiers.Any(SyntaxKind.RefKeyword))
Expand Down
11 changes: 11 additions & 0 deletions test/Microsoft.Windows.CsWin32.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ public void TryGetEnumName(string candidate, string? declaringEnum)
Assert.Equal(declaringEnum, actualDeclaringEnum);
}

[Theory]
[MemberData(nameof(TFMData))]
public void CoCreateInstance(string tfm)
{
this.compilation = this.starterCompilations[tfm];
this.generator = this.CreateGenerator(includeDocs: true);
Assert.True(this.generator.TryGenerateExternMethod("CoCreateInstance", out _));
this.CollectGeneratedCode(this.generator);
this.AssertNoDiagnostics();
}

[Theory]
[MemberData(nameof(TFMData))]
public void SimplestMethod(string tfm)
Expand Down

0 comments on commit 62df282

Please sign in to comment.