Skip to content

Commit bba26bc

Browse files
authored
chore: Add nullable annotations to projects (#3011)
* chore: add nullable annotations * chore: apply code formatter to fix mixed CRLF/LF
1 parent 4e93b69 commit bba26bc

25 files changed

+137
-111
lines changed

samples/BenchmarkDotNet.Samples.FSharp/BenchmarkDotNet.Samples.FSharp.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<GenerateProgramFile>false</GenerateProgramFile>
77
<!-- Disable parallel tests between TargetFrameworks -->
88
<TestTfmsInParallel>false</TestTfmsInParallel>
9+
<Nullable>enable</Nullable>
910
</PropertyGroup>
1011
<ItemGroup>
1112
<Compile Include="Program.fs" />

samples/BenchmarkDotNet.Samples/BenchmarkDotNet.Samples.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<GenerateProgramFile>false</GenerateProgramFile>
1515
<!-- Disable parallel tests between TargetFrameworks -->
1616
<TestTfmsInParallel>false</TestTfmsInParallel>
17+
<Nullable>enable</Nullable>
1718
</PropertyGroup>
1819
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
1920
<Reference Include="System.Reflection" />

samples/BenchmarkDotNet.Samples/IntroComparableComplexParam.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ public ComplexParam(int value, string name)
3131

3232
public int CompareTo(ComplexParam? other) => other == null ? 1 : Value.CompareTo(other.Value);
3333

34-
public int CompareTo(object obj) => obj is ComplexParam other ? CompareTo(other) : throw new ArgumentException();
34+
public int CompareTo(object? obj)
35+
{
36+
if (obj == null)
37+
return 1;
38+
39+
if (obj is not ComplexParam other)
40+
throw new ArgumentException();
41+
42+
return CompareTo(other);
43+
}
3544
}
3645
}
3746
}

samples/BenchmarkDotNet.Samples/IntroDotMemoryDiagnoser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class IntroDotMemoryDiagnoser
1313
[Params(1024)]
1414
public int Size;
1515

16-
private byte[] dataArray;
17-
private IEnumerable<byte> dataEnumerable;
16+
private byte[] dataArray = default!;
17+
private IEnumerable<byte> dataEnumerable = default!;
1818

1919
[GlobalSetup]
2020
public void Setup()

samples/BenchmarkDotNet.Samples/IntroMemoryRandomization.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class IntroMemoryRandomization
88
[Params(512 * 4)]
99
public int Size;
1010

11-
private int[] array;
12-
private int[] destination;
11+
private int[] array = default!;
12+
private int[] destination = default!;
1313

1414
[GlobalSetup]
1515
public void Setup()

samples/BenchmarkDotNet.Samples/IntroOrderManual.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ from benchmark in benchmarksCase
3030

3131
public IEnumerable<BenchmarkCase> GetSummaryOrder(ImmutableArray<BenchmarkCase> benchmarksCase, Summary summary) =>
3232
from benchmark in benchmarksCase
33-
orderby summary[benchmark].ResultStatistics.Mean
33+
orderby summary[benchmark]?.ResultStatistics?.Mean
3434
select benchmark;
3535

36-
public string GetHighlightGroupKey(BenchmarkCase benchmarkCase) => null;
36+
public string? GetHighlightGroupKey(BenchmarkCase benchmarkCase) => null;
3737

3838
public string GetLogicalGroupKey(ImmutableArray<BenchmarkCase> allBenchmarksCases, BenchmarkCase benchmarkCase) =>
3939
benchmarkCase.Job.DisplayInfo + "_" + benchmarkCase.Parameters.DisplayInfo;

samples/BenchmarkDotNet.Samples/IntroSetupCleanupGlobal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class IntroSetupCleanupGlobal
77
[Params(10, 100, 1000)]
88
public int N;
99

10-
private int[] data;
10+
private int[] data = default!;
1111

1212
[GlobalSetup]
1313
public void GlobalSetup()

samples/BenchmarkDotNet.Samples/IntroSmokeValueTypes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public struct EmptyStruct { }
2222
[Benchmark] public EmptyStruct ReturnEmptyStruct() => new EmptyStruct();
2323

2424
[Benchmark] public ValueTuple<int> ReturnGenericStructOfValueType() => new ValueTuple<int>(0);
25-
[Benchmark] public ValueTuple<object> ReturnGenericStructOfReferenceType() => new ValueTuple<object>(null);
25+
[Benchmark] public ValueTuple<object?> ReturnGenericStructOfReferenceType() => new ValueTuple<object?>(null);
2626

2727
[Benchmark] public ValueTask<int> ReturnValueTaskOfValueType() => new ValueTask<int>(0);
28-
[Benchmark] public ValueTask<object> ReturnValueTaskOfReferenceType() => new ValueTask<object>(result: null);
28+
[Benchmark] public ValueTask<object?> ReturnValueTaskOfReferenceType() => new ValueTask<object?>(result: null);
2929

3030
[Benchmark] public byte ReturnByte() => 0;
3131
public struct Byte1 { public byte _1; }

samples/BenchmarkDotNet.Samples/IntroThreadingDiagnoser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public void CompleteOneWorkItem()
1111
{
1212
ManualResetEvent done = new ManualResetEvent(initialState: false);
1313

14-
ThreadPool.QueueUserWorkItem(m => (m as ManualResetEvent).Set(), done);
14+
ThreadPool.QueueUserWorkItem(m => (m as ManualResetEvent)?.Set(), done);
1515

1616
done.WaitOne();
1717
}

samples/BenchmarkDotNet.Samples/IntroWasm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void Run()
3636

3737
WasmRuntime runtime = new WasmRuntime(msBuildMoniker: "net5.0");
3838
NetCoreAppSettings netCoreAppSettings = new NetCoreAppSettings(
39-
targetFrameworkMoniker: "net5.0", runtimeFrameworkVersion: null, name: "Wasm",
39+
targetFrameworkMoniker: "net5.0", runtimeFrameworkVersion: "", name: "Wasm",
4040
customDotNetCliPath: cliPath);
4141
IToolchain toolChain = WasmToolchain.From(netCoreAppSettings);
4242

0 commit comments

Comments
 (0)