Skip to content

Commit 2a8bab5

Browse files
alinasmirnovaAndreyAkinshin
authored andcommitted
Fixed nullability warnings for some files from BenchmarkDotNet project
1 parent 3860e4a commit 2a8bab5

File tree

11 files changed

+31
-28
lines changed

11 files changed

+31
-28
lines changed

src/BenchmarkDotNet/Analysers/Conclusion.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static Conclusion CreateWarning(string analyserId, string message, Benchm
3838
public static Conclusion CreateError(string analyserId, string message, BenchmarkReport? report = null, bool mergeable = true)
3939
=> new Conclusion(analyserId, ConclusionKind.Error, message, report, mergeable);
4040

41-
public bool Equals(Conclusion other)
41+
public bool Equals(Conclusion? other)
4242
{
4343
if (ReferenceEquals(null, other))
4444
return false;
@@ -49,7 +49,7 @@ public bool Equals(Conclusion other)
4949
return string.Equals(AnalyserId, other.AnalyserId) && Kind == other.Kind && string.Equals(Message, other.Message);
5050
}
5151

52-
public override bool Equals(object obj)
52+
public override bool Equals(object? obj)
5353
{
5454
if (ReferenceEquals(null, obj))
5555
return false;

src/BenchmarkDotNet/Analysers/ZeroMeasurementHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static bool CheckZeroMeasurementOneSample(double[] results, double thresh
2020
/// Checks distribution against Zero Measurement hypothesis in case of two samples
2121
/// </summary>
2222
/// <returns>True if measurement is ZeroMeasurement</returns>
23-
public static bool CheckZeroMeasurementTwoSamples(double[] workload, double[] overhead, Threshold threshold = null)
23+
public static bool CheckZeroMeasurementTwoSamples(double[] workload, double[] overhead, Threshold? threshold = null)
2424
{
2525
if (workload.Length < 3 || overhead.Length < 3)
2626
return false;

src/BenchmarkDotNet/Attributes/Filters/AotFilterAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace BenchmarkDotNet.Attributes.Filters
44
{
55
public class AotFilterAttribute : FilterConfigBaseAttribute
66
{
7-
public AotFilterAttribute(string reason = null)
7+
public AotFilterAttribute(string? reason = null)
88
: base(new SimpleFilter(benchmark => !benchmark.GetRuntime().IsAOT))
99
{
1010
}

src/BenchmarkDotNet/Attributes/Jobs/SimpleJobAttribute.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public SimpleJobAttribute(
1818
int warmupCount = DefaultValue,
1919
int iterationCount = DefaultValue,
2020
int invocationCount = DefaultValue,
21-
string id = null,
21+
string? id = null,
2222
bool baseline = false
2323
) : base(CreateJob(id, launchCount, warmupCount, iterationCount, invocationCount, null, baseline)) { }
2424

@@ -29,7 +29,7 @@ public SimpleJobAttribute(
2929
int warmupCount = DefaultValue,
3030
int iterationCount = DefaultValue,
3131
int invocationCount = DefaultValue,
32-
string id = null,
32+
string? id = null,
3333
bool baseline = false
3434
) : base(CreateJob(id, launchCount, warmupCount, iterationCount, invocationCount, runStrategy, baseline)) { }
3535

@@ -40,7 +40,7 @@ public SimpleJobAttribute(
4040
int warmupCount = DefaultValue,
4141
int iterationCount = DefaultValue,
4242
int invocationCount = DefaultValue,
43-
string id = null,
43+
string? id = null,
4444
bool baseline = false
4545
) : base(CreateJob(id, launchCount, warmupCount, iterationCount, invocationCount, null, baseline, runtimeMoniker)) { }
4646

@@ -52,11 +52,11 @@ public SimpleJobAttribute(
5252
int warmupCount = DefaultValue,
5353
int iterationCount = DefaultValue,
5454
int invocationCount = DefaultValue,
55-
string id = null,
55+
string? id = null,
5656
bool baseline = false
5757
) : base(CreateJob(id, launchCount, warmupCount, iterationCount, invocationCount, runStrategy, baseline, runtimeMoniker)) { }
5858

59-
private static Job CreateJob(string id, int launchCount, int warmupCount, int iterationCount, int invocationCount, RunStrategy? runStrategy,
59+
private static Job CreateJob(string? id, int launchCount, int warmupCount, int iterationCount, int invocationCount, RunStrategy? runStrategy,
6060
bool baseline, RuntimeMoniker runtimeMoniker = RuntimeMoniker.HostProcess)
6161
{
6262
var job = new Job(id);

src/BenchmarkDotNet/Characteristics/CharacteristicObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected CharacteristicObject()
4444
sharedValues = new Dictionary<Characteristic, object>();
4545
}
4646

47-
protected CharacteristicObject(string id) : this()
47+
protected CharacteristicObject(string? id) : this()
4848
{
4949
if (!string.IsNullOrEmpty(id))
5050
{
@@ -98,7 +98,7 @@ private static void AssertIsAssignable(Characteristic characteristic, object val
9898

9999
#region Properties
100100

101-
private CharacteristicObject Owner { get; set; }
101+
private CharacteristicObject? Owner { get; set; }
102102

103103
protected CharacteristicObject OwnerOrSelf => Owner ?? this;
104104

src/BenchmarkDotNet/Characteristics/CharacteristicObject`1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public abstract class CharacteristicObject<T> : CharacteristicObject
88
{
99
protected CharacteristicObject() { }
1010

11-
protected CharacteristicObject(string id) : base(id) { }
11+
protected CharacteristicObject(string? id) : base(id) { }
1212

1313
public new T Apply(CharacteristicObject other) => (T)ApplyCore(other);
1414

src/BenchmarkDotNet/Characteristics/Characteristic`1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Characteristic<[DynamicallyAccessedMembers(CharacteristicObject.Cha
88
internal Characteristic(
99
string id,
1010
Type declaringType,
11-
Func<CharacteristicObject, T, T> resolver,
11+
Func<CharacteristicObject, T, T>? resolver,
1212
T fallbackValue,
1313
bool ignoreOnApply,
1414
bool dontShowInSummary = false)
@@ -18,7 +18,7 @@ internal Characteristic(
1818
FallbackValue = fallbackValue;
1919
}
2020

21-
private Func<CharacteristicObject, T, T> Resolver { get; }
21+
private Func<CharacteristicObject, T, T>? Resolver { get; }
2222

2323
public T FallbackValue { get; }
2424

src/BenchmarkDotNet/Code/ArrayParam.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ namespace BenchmarkDotNet.Code
1010
internal static class ArrayParam
1111
{
1212
public static string GetDisplayString(Array array)
13-
=> $"{array.GetType().GetElementType().GetDisplayName()}[{array.Length}]";
13+
=> $"{array.GetType().GetElementType()?.GetDisplayName()}[{array.Length}]";
1414
}
1515

1616
public class ArrayParam<T> : IParam
1717
{
1818
private readonly T[] array;
19-
private readonly Func<T, string> toSourceCode;
19+
private readonly Func<T, string>? toSourceCode;
2020

21-
private ArrayParam(T[] array, Func<T, string> toSourceCode = null)
21+
private ArrayParam(T[] array, Func<T, string>? toSourceCode = null)
2222
{
2323
this.array = array;
2424
this.toSourceCode = toSourceCode;
@@ -45,19 +45,22 @@ public string ToSourceCode()
4545
/// </param>
4646
[PublicAPI] public static ArrayParam<T> ForComplexTypes(T[] array, Func<T, string> toSourceCode) => new ArrayParam<T>(array, toSourceCode);
4747

48-
internal static IParam FromObject(object array)
48+
internal static IParam? FromObject(object array)
4949
{
5050
var type = array.GetType();
5151
if (!type.IsArray)
5252
throw new InvalidOperationException("The argument must be an array");
53-
if (!SourceCodeHelper.IsCompilationTimeConstant(type.GetElementType()))
53+
var elementType = type.GetElementType();
54+
if (elementType == null)
55+
throw new InvalidOperationException("Failed to determine type of array elements");
56+
if (!SourceCodeHelper.IsCompilationTimeConstant(elementType))
5457
throw new InvalidOperationException("The argument must be an array of primitives");
5558

56-
var arrayParamType = typeof(ArrayParam<>).MakeGenericType(type.GetElementType());
59+
var arrayParamType = typeof(ArrayParam<>).MakeGenericType(elementType);
5760

5861
var methodInfo = arrayParamType.GetMethod(nameof(ForPrimitives), BindingFlags.Public | BindingFlags.Static)
5962
?? throw new InvalidOperationException($"{nameof(ForPrimitives)} not found");
60-
return (IParam)methodInfo.Invoke(null, new[]{ array});
63+
return (IParam?)methodInfo.Invoke(null, new[]{ array});
6164
}
6265
}
6366
}

src/BenchmarkDotNet/Code/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public SmartStringBuilder(string text)
296296
builder = new StringBuilder(text);
297297
}
298298

299-
public SmartStringBuilder Replace(string oldValue, string newValue)
299+
public SmartStringBuilder Replace(string oldValue, string? newValue)
300300
{
301301
if (originalText.Contains(oldValue))
302302
builder.Replace(oldValue, newValue);

src/BenchmarkDotNet/Jobs/Job.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public sealed class Job : JobMode<Job>
3030
public static readonly Job InProcess = new Job(nameof(InProcess), InfrastructureMode.InProcess);
3131
public static readonly Job InProcessDontLogOutput = new Job(nameof(InProcessDontLogOutput), InfrastructureMode.InProcessDontLogOutput);
3232

33-
public Job() : this((string)null) { }
33+
public Job() : this((string?)null) { }
3434

35-
public Job(string id) : base(id)
35+
public Job(string? id) : base(id)
3636
{
3737
EnvironmentCharacteristic[this] = new EnvironmentMode();
3838
RunCharacteristic[this] = new RunMode();
@@ -41,20 +41,20 @@ public Job(string id) : base(id)
4141
MetaCharacteristic[this] = new MetaMode();
4242
}
4343

44-
public Job(CharacteristicObject other) : this((string)null, other)
44+
public Job(CharacteristicObject other) : this((string?)null, other)
4545
{
4646
}
4747

4848
public Job(params CharacteristicObject[] others) : this(null, others)
4949
{
5050
}
5151

52-
public Job(string id, CharacteristicObject other) : this(id)
52+
public Job(string? id, CharacteristicObject other) : this(id)
5353
{
5454
Apply(other);
5555
}
5656

57-
public Job(string id, params CharacteristicObject[] others) : this(id)
57+
public Job(string? id, params CharacteristicObject[] others) : this(id)
5858
{
5959
Apply(others);
6060
}

0 commit comments

Comments
 (0)