Skip to content

Commit 3ee8664

Browse files
authored
Merge pull request #65 from sharwell/nullable
Enable nullable reference types
2 parents 6cdf3fe + b0f7bf6 commit 3ee8664

File tree

124 files changed

+1558
-1341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1558
-1341
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,6 @@ csharp_space_between_method_declaration_name_and_open_parenthesis = false
133133
csharp_space_between_method_declaration_parameter_list_parentheses = false
134134
csharp_space_between_parentheses = false
135135
csharp_space_between_square_brackets = false
136+
137+
# RS0041: Public members should not use oblivious types
138+
dotnet_diagnostic.RS0041.severity = none

Directory.Build.props

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@
22
<Project>
33

44
<PropertyGroup>
5-
<LangVersion>7.3</LangVersion>
5+
<LangVersion>8.0</LangVersion>
66
<Features>strict</Features>
77
</PropertyGroup>
88

9+
<!-- Enable nullable reference types -->
10+
<PropertyGroup>
11+
<Nullable>enable</Nullable>
12+
<GenerateNullableAttributes>false</GenerateNullableAttributes>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="TunnelVisionLabs.ReferenceAssemblyAnnotator" Version="1.0.0-alpha.154" PrivateAssets="all" />
17+
<PackageDownload Include="Microsoft.NETCore.App.Ref" Version="[3.1.0]" />
18+
</ItemGroup>
19+
920
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
1021
<!-- Ideally this is always enabled, but that tends to hurt developer productivity -->
1122
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -58,7 +69,7 @@
5869

5970
<!-- Public API -->
6071
<ItemGroup>
61-
<PackageReference Include="DotNetAnalyzers.PublicApiAnalyzer" Version="1.0.0-beta.12" PrivateAssets="all" />
72+
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.0-beta3.20367.1" PrivateAssets="all" />
6273
</ItemGroup>
6374

6475
<ItemGroup>

NuGet.Config

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
6+
<add key="dotnet5" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json" />
7+
</packageSources>
8+
<disabledPackageSources>
9+
<clear />
10+
</disabledPackageSources>
11+
</configuration>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#nullable enable

TunnelVisionLabs.Collections.Trees.Experimental/TunnelVisionLabs.Collections.Trees.Experimental.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33

44
<PropertyGroup>
5-
<TargetFrameworks>net45;netstandard1.1;netstandard2.0</TargetFrameworks>
5+
<TargetFrameworks>net45;netstandard1.1;netstandard2.0;netstandard2.1</TargetFrameworks>
66
<RootNamespace>TunnelVisionLabs.Collections.Trees</RootNamespace>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
</PropertyGroup>

TunnelVisionLabs.Collections.Trees.Test/AbstractSetTest.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public abstract class AbstractSetTest
1616
public void TestUnionWith()
1717
{
1818
ISet<int> set = CreateSet<int>();
19-
Assert.Throws<ArgumentNullException>(() => set.UnionWith(null));
19+
Assert.Throws<ArgumentNullException>(() => set.UnionWith(null!));
2020

2121
set.UnionWith(TransformEnumerableForSetOperation(Enumerable.Range(0, 7)));
2222
set.UnionWith(TransformEnumerableForSetOperation(Enumerable.Range(5, 5)));
@@ -27,7 +27,7 @@ public void TestUnionWith()
2727
public void TestExceptWith()
2828
{
2929
ISet<int> set = CreateSet<int>();
30-
Assert.Throws<ArgumentNullException>(() => set.ExceptWith(null));
30+
Assert.Throws<ArgumentNullException>(() => set.ExceptWith(null!));
3131

3232
// Return without iterating if the set is already empty
3333
set.ExceptWith(EverythingThrowsEnumerable<int>.Instance);
@@ -49,7 +49,7 @@ public void TestExceptWith()
4949
public void TestIntersectWith()
5050
{
5151
ISet<int> set = CreateSet<int>();
52-
Assert.Throws<ArgumentNullException>(() => set.IntersectWith(null));
52+
Assert.Throws<ArgumentNullException>(() => set.IntersectWith(null!));
5353

5454
// Return without iterating if the set is already empty
5555
set.IntersectWith(EverythingThrowsEnumerable<int>.Instance);
@@ -76,7 +76,7 @@ public void TestSymmetricExceptWith()
7676
{
7777
ISet<int> set = CreateSet<int>();
7878
ISet<int> second = CreateSet<int>();
79-
Assert.Throws<ArgumentNullException>(() => set.SymmetricExceptWith(null));
79+
Assert.Throws<ArgumentNullException>(() => set.SymmetricExceptWith(null!));
8080

8181
// Test behavior when the current set is empty
8282
set.SymmetricExceptWith(TransformEnumerableForSetOperation(new[] { 1, 5, 3 }));
@@ -110,7 +110,7 @@ public void TestSymmetricExceptWith()
110110
public void TestIsProperSubsetOf()
111111
{
112112
ISet<int> set = CreateSet<int>();
113-
Assert.Throws<ArgumentNullException>(() => set.IsProperSubsetOf(null));
113+
Assert.Throws<ArgumentNullException>(() => set.IsProperSubsetOf(null!));
114114

115115
// Test behavior when the current set is empty
116116
Assert.False(set.IsProperSubsetOf(TransformEnumerableForSetOperation(Enumerable.Empty<int>())));
@@ -145,7 +145,7 @@ public void TestIsProperSubsetOf()
145145
public void TestIsProperSupersetOf()
146146
{
147147
ISet<int> set = CreateSet<int>();
148-
Assert.Throws<ArgumentNullException>(() => set.IsProperSupersetOf(null));
148+
Assert.Throws<ArgumentNullException>(() => set.IsProperSupersetOf(null!));
149149

150150
// Return without iterating if the set is already empty
151151
Assert.False(set.IsProperSupersetOf(EverythingThrowsEnumerable<int>.Instance));
@@ -183,7 +183,7 @@ public void TestIsProperSupersetOf()
183183
public void TestIsSubsetOf()
184184
{
185185
ISet<int> set = CreateSet<int>();
186-
Assert.Throws<ArgumentNullException>(() => set.IsSubsetOf(null));
186+
Assert.Throws<ArgumentNullException>(() => set.IsSubsetOf(null!));
187187

188188
// Return without iterating if the set is already empty
189189
Assert.True(set.IsSubsetOf(EverythingThrowsEnumerable<int>.Instance));
@@ -217,7 +217,7 @@ public void TestIsSubsetOf()
217217
public void TestIsSupersetOf()
218218
{
219219
ISet<int> set = CreateSet<int>();
220-
Assert.Throws<ArgumentNullException>(() => set.IsSupersetOf(null));
220+
Assert.Throws<ArgumentNullException>(() => set.IsSupersetOf(null!));
221221

222222
// Test IsSupersetOf self
223223
set.Add(1);
@@ -252,7 +252,7 @@ public void TestIsSupersetOf()
252252
public void TestOverlaps()
253253
{
254254
ISet<int> set = CreateSet<int>();
255-
Assert.Throws<ArgumentNullException>(() => set.Overlaps(null));
255+
Assert.Throws<ArgumentNullException>(() => set.Overlaps(null!));
256256

257257
// Return without iterating if the set is already empty
258258
Assert.False(set.Overlaps(EverythingThrowsEnumerable<int>.Instance));
@@ -272,7 +272,7 @@ public void TestOverlaps()
272272
public void TestSetEquals()
273273
{
274274
ISet<int> set = CreateSet<int>();
275-
Assert.Throws<ArgumentNullException>(() => set.SetEquals(null));
275+
Assert.Throws<ArgumentNullException>(() => set.SetEquals(null!));
276276

277277
// Test behavior when the current set is empty
278278
Assert.True(set.SetEquals(TransformEnumerableForSetOperation(Enumerable.Empty<int>())));
@@ -341,7 +341,7 @@ protected static void TestICollectionInterfaceImpl(ICollection collection, bool
341341
{
342342
var copy = new object[collection.Count];
343343

344-
Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null, 0));
344+
Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null!, 0));
345345
Assert.Throws<ArgumentException>(() => collection.CopyTo(new object[1, collection.Count], 0));
346346
Assert.Throws<ArgumentException>(() => collection.CopyTo(Array.CreateInstance(typeof(object), lengths: new[] { collection.Count }, lowerBounds: new[] { -1 }), 0));
347347
Assert.Throws<ArgumentOutOfRangeException>(() => collection.CopyTo(copy, -1));
@@ -368,7 +368,7 @@ protected static void TestICollectionInterfaceImpl(ICollection collection, bool
368368
{
369369
var copy = new int[collection.Count];
370370

371-
Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null, 0));
371+
Assert.Throws<ArgumentNullException>(() => collection.CopyTo(null!, 0));
372372
Assert.Throws<ArgumentException>(() => collection.CopyTo(new int[1, collection.Count], 0));
373373
Assert.Throws<ArgumentException>(() => collection.CopyTo(Array.CreateInstance(typeof(int), lengths: new[] { collection.Count }, lowerBounds: new[] { -1 }), 0));
374374
Assert.Throws<ArgumentOutOfRangeException>(() => collection.CopyTo(copy, -1));

TunnelVisionLabs.Collections.Trees.Test/GeneratorTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace TunnelVisionLabs.Collections.Trees.Test
55
{
6+
using System.Diagnostics;
67
using System.Reflection;
78
using Xunit;
89

@@ -23,7 +24,8 @@ public void TestSeed()
2324

2425
void ResetSeed(int? seed)
2526
{
26-
FieldInfo seedField = typeof(Generator).GetField("_seed", BindingFlags.Static | BindingFlags.NonPublic);
27+
FieldInfo? seedField = typeof(Generator).GetField("_seed", BindingFlags.Static | BindingFlags.NonPublic);
28+
Debug.Assert(seedField is object, $"Assertion failed: {nameof(seedField)} is object");
2729
seedField.SetValue(null, seed);
2830
}
2931
}

TunnelVisionLabs.Collections.Trees.Test/Immutable/AbstractImmutableDictionaryTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public void TestRemove()
162162
dictionary.Remove(1));
163163
}
164164

165-
protected abstract IImmutableDictionary<TKey, TValue> CreateDictionary<TKey, TValue>();
165+
protected abstract IImmutableDictionary<TKey, TValue> CreateDictionary<TKey, TValue>()
166+
where TKey : notnull;
166167
}
167168
}

TunnelVisionLabs.Collections.Trees.Test/Immutable/AbstractImmutableSetTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ protected static void TestICollectionInterfaceImpl(ICollection collection, bool
331331
Assert.NotNull(collection.SyncRoot);
332332
Assert.Same(collection, collection.SyncRoot);
333333

334-
Assert.Throws<ArgumentNullException>("array", () => collection.CopyTo(null, 0));
334+
Assert.Throws<ArgumentNullException>("array", () => collection.CopyTo(null!, 0));
335335
Assert.Throws<ArgumentException>(() => collection.CopyTo(new int[collection.Count, 1], 0));
336336

337337
void CopyToArrayWithNonZeroLowerBound() => collection.CopyTo(Array.CreateInstance(typeof(int), lengths: new[] { collection.Count }, lowerBounds: new[] { 1 }), 0);

0 commit comments

Comments
 (0)