fix: suppress MA0077 on ref struct types and fix variable shadowing

ref struct types (BatchOutputs, BatchInputs, ScalarState, WorkBuffers)
cannot implement IEquatable<T> — C# prohibits interface implementation
on ref structs. Added #pragma warning disable/restore MA0077 at type
declaration level in AccBands.cs, Aberr.cs, Apz.cs (9 ref structs).

Renamed local 'output' to 'result' in Wma.Coverage.Tests.cs to avoid
shadowing the primary constructor ITestOutputHelper parameter (S1117/MA0084).
This commit is contained in:
Miha Kralj
2026-03-03 12:42:42 -08:00
parent 3e858ca39e
commit 7737098a54
4 changed files with 24 additions and 6 deletions
+6
View File
@@ -412,6 +412,7 @@ public sealed class Aberr : ITValuePublisher, IDisposable
/// <summary>
/// Output buffers for batch Aberr calculation.
/// </summary>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
#pragma warning disable S1104 // Fields should not have public accessibility
public readonly ref struct BatchOutputs
@@ -447,10 +448,12 @@ public sealed class Aberr : ITValuePublisher, IDisposable
public static bool operator ==(BatchOutputs left, BatchOutputs right) => left.Equals(right);
public static bool operator !=(BatchOutputs left, BatchOutputs right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Internal state for scalar calculation.
/// </summary>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
[SuppressMessage("NDepend", "ND1903:StructuresShouldBeImmutable", Justification = "Mutable calculation state accumulator by design")]
private ref struct ScalarState
@@ -471,10 +474,12 @@ public sealed class Aberr : ITValuePublisher, IDisposable
public static bool operator ==(ScalarState left, ScalarState right) => left.Equals(right);
public static bool operator !=(ScalarState left, ScalarState right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Working buffers for batch calculation.
/// </summary>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
private readonly ref struct WorkBuffers(Span<double> source, Span<double> deviation)
{
@@ -492,6 +497,7 @@ public sealed class Aberr : ITValuePublisher, IDisposable
public static bool operator ==(WorkBuffers left, WorkBuffers right) => left.Equals(right);
public static bool operator !=(WorkBuffers left, WorkBuffers right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Calculates Aberr for the entire TSeries using a new instance.
+8
View File
@@ -474,6 +474,7 @@ public sealed class AccBands : ITValuePublisher, IDisposable
/// Public Span fields are intentional: ref structs cannot use auto-properties with Span&lt;T&gt;
/// and direct field access provides optimal performance for this high-throughput API.
/// </remarks>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
#pragma warning disable S1104 // Fields should not have public accessibility
public readonly ref struct BatchOutputs
@@ -509,10 +510,12 @@ public sealed class AccBands : ITValuePublisher, IDisposable
public static bool operator ==(BatchOutputs left, BatchOutputs right) => left.Equals(right);
public static bool operator !=(BatchOutputs left, BatchOutputs right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Input buffers for batch AccBands calculation.
/// </summary>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
#pragma warning disable S1104 // Fields should not have public accessibility
public readonly ref struct BatchInputs
@@ -548,10 +551,12 @@ public sealed class AccBands : ITValuePublisher, IDisposable
public static bool operator ==(BatchInputs left, BatchInputs right) => left.Equals(right);
public static bool operator !=(BatchInputs left, BatchInputs right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Internal state for scalar calculation.
/// </summary>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
[SuppressMessage("NDepend", "ND1903:StructuresShouldBeImmutable", Justification = "Mutable calculation state accumulator by design")]
private ref struct ScalarState
@@ -576,10 +581,12 @@ public sealed class AccBands : ITValuePublisher, IDisposable
public static bool operator ==(ScalarState left, ScalarState right) => left.Equals(right);
public static bool operator !=(ScalarState left, ScalarState right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Working buffers for batch calculation.
/// </summary>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
private readonly ref struct WorkBuffers(Span<double> adjHigh, Span<double> adjLow, Span<double> close)
{
@@ -600,6 +607,7 @@ public sealed class AccBands : ITValuePublisher, IDisposable
public static bool operator ==(WorkBuffers left, WorkBuffers right) => left.Equals(right);
public static bool operator !=(WorkBuffers left, WorkBuffers right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Calculates AccBands for the entire TBarSeries using a new instance.
+4
View File
@@ -411,6 +411,7 @@ public sealed class Apz : ITValuePublisher
/// <summary>
/// Output buffers for batch APZ calculation.
/// </summary>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
#pragma warning disable S1104 // Fields should not have public accessibility
public readonly ref struct BatchOutputs
@@ -446,10 +447,12 @@ public sealed class Apz : ITValuePublisher
public static bool operator ==(BatchOutputs left, BatchOutputs right) => left.Equals(right);
public static bool operator !=(BatchOutputs left, BatchOutputs right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Internal state for scalar calculation.
/// </summary>
#pragma warning disable MA0077 // ref struct cannot implement interfaces
[StructLayout(LayoutKind.Auto)]
[SuppressMessage("NDepend", "ND1903:StructuresShouldBeImmutable", Justification = "Mutable calculation state accumulator by design")]
private ref struct ScalarState
@@ -476,6 +479,7 @@ public sealed class Apz : ITValuePublisher
public static bool operator ==(ScalarState left, ScalarState right) => left.Equals(right);
public static bool operator !=(ScalarState left, ScalarState right) => !left.Equals(right);
}
#pragma warning restore MA0077
/// <summary>
/// Calculates APZ for the entire TBarSeries using a new instance.
+6 -6
View File
@@ -18,12 +18,12 @@ public class WmaCoverageTests(ITestOutputHelper output)
source[i] = i;
}
double[] output = new double[len];
double[] result = new double[len];
// This should trigger CalculateScalarCore internally
Wma.Batch(source.AsSpan(), output.AsSpan(), period);
Wma.Batch(source.AsSpan(), result.AsSpan(), period);
Assert.NotEqual(0, output[period]);
Assert.NotEqual(0, result[period]);
}
[Fact]
@@ -94,11 +94,11 @@ public class WmaCoverageTests(ITestOutputHelper output)
source[i] = i;
}
double[] output = new double[len];
double[] result = new double[len];
InvokePrivateStaticMethod_WithSpans("CalculateScalarCore", source, output, period);
InvokePrivateStaticMethod_WithSpans("CalculateScalarCore", source, result, period);
Assert.NotEqual(0, output[period]);
Assert.NotEqual(0, result[period]);
}
private delegate void CoreDelegate(ReadOnlySpan<double> source, Span<double> output, int period);