Skip to content

Commit e7ec1b4

Browse files
authored
Fix varying parameters used for inferred length (#33)
* Add flaky test for inferred length in doc string The parameter used for inferring the length is not deterministic because of the non-determinism of hash set. This leads to changing logic between builds, shown by this flaky test. * Switch to deterministic parameter Use the first parameter for inferring the length as intended by the code
1 parent a196f04 commit e7ec1b4

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

MKL.NET.WrapperGenerator.Tests/GeneratorTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public static unsafe extern void dummy(int M, int N,
4949

5050
generatorResult.Generator.Should().BeSameAs(generator);
5151
generatorResult.Diagnostics.Should().BeEmpty();
52-
generatorResult.GeneratedSources.Should().HaveCount(1);
52+
generatorResult.GeneratedSources.Should().ContainSingle()
53+
.Which.SourceText.ToString().Should().Contain(
54+
"///<remarks>" +
55+
"This version infers the length parameter <c>N</c> from <paramref name=\"A\" />'s length.</remarks>");
5356
generatorResult.Exception.Should().BeNull();
5457
}
5558

MKL.NET.WrapperGenerator/WrapperGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public void Initialize(GeneratorInitializationContext context)
3636
return candidates[0];
3737
}
3838

39-
private static (ISet<ParameterSyntax> changed, ParameterListSyntax newList)
39+
private static (IList<ParameterSyntax> changed, ParameterListSyntax newList)
4040
TransformParameters(MethodDeclarationSyntax mds, Func<ParameterSyntax, ParameterSyntax?> f)
4141
{
42-
var changed = mds.ParameterList.Parameters.Select(ps => f(ps) is null ? null : ps).Where(ps => ps != null).ToImmutableHashSet();
42+
var changed = mds.ParameterList.Parameters.Select(ps => f(ps) is null ? null : ps).Where(ps => ps != null).ToImmutableList();
4343
var newList = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(mds.ParameterList.Parameters.Select(ps => f(ps) ?? ps)));
4444

4545
return (changed!, newList);
@@ -57,7 +57,7 @@ private enum AdditionalTransformation
5757

5858
void WriterTransformedMethod(
5959
MethodDeclarationSyntax mds, ClassDeclarationSyntax nativeCds,
60-
(ISet<ParameterSyntax> changed, ParameterListSyntax newList) transformation, StringBuilder sb,
60+
(IList<ParameterSyntax> changed, ParameterListSyntax newList) transformation, StringBuilder sb,
6161
AdditionalTransformation trafo)
6262
{
6363
(ParameterSyntax lengthParam, string takeLengthFrom)? lengthOptions = null;

0 commit comments

Comments
 (0)