Skip to content

Commit 7a24a53

Browse files
authored
Merge pull request dotnet#24258 from dotnet/NullableFeature
Merge nullable feature into master
2 parents 3cf188a + c3f5c90 commit 7a24a53

File tree

197 files changed

+3069
-2984
lines changed

Some content is hidden

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

197 files changed

+3069
-2984
lines changed

src/System.Private.CoreLib/shared/System/AppDomain.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ public void SetThreadPrincipal(IPrincipal principal)
399399
case PrincipalPolicy.UnauthenticatedPrincipal:
400400
if (s_getUnauthenticatedPrincipal == null)
401401
{
402-
Type type = Type.GetType("System.Security.Principal.GenericPrincipal, System.Security.Claims", throwOnError: true);
403-
MethodInfo mi = type.GetMethod("GetDefaultInstance", BindingFlags.NonPublic | BindingFlags.Static);
402+
Type type = Type.GetType("System.Security.Principal.GenericPrincipal, System.Security.Claims", throwOnError: true)!;
403+
MethodInfo? mi = type.GetMethod("GetDefaultInstance", BindingFlags.NonPublic | BindingFlags.Static);
404404
Debug.Assert(mi != null);
405405
// Don't throw PNSE if null like for WindowsPrincipal as UnauthenticatedPrincipal should
406406
// be available on all platforms.
@@ -414,8 +414,8 @@ public void SetThreadPrincipal(IPrincipal principal)
414414
case PrincipalPolicy.WindowsPrincipal:
415415
if (s_getWindowsPrincipal == null)
416416
{
417-
Type type = Type.GetType("System.Security.Principal.WindowsPrincipal, System.Security.Principal.Windows", throwOnError: true);
418-
MethodInfo mi = type.GetMethod("GetDefaultInstance", BindingFlags.NonPublic | BindingFlags.Static);
417+
Type type = Type.GetType("System.Security.Principal.WindowsPrincipal, System.Security.Principal.Windows", throwOnError: true)!;
418+
MethodInfo? mi = type.GetMethod("GetDefaultInstance", BindingFlags.NonPublic | BindingFlags.Static);
419419
if (mi == null)
420420
{
421421
throw new PlatformNotSupportedException(SR.PlatformNotSupported_Principal);

src/System.Private.CoreLib/shared/System/Array.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)
384384

385385
for (int i = (this.Length >= 8 ? this.Length - 8 : 0); i < this.Length; i++)
386386
{
387-
ret = CombineHashCodes(ret, comparer!.GetHashCode(GetValue(i))); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
387+
ret = CombineHashCodes(ret, comparer!.GetHashCode(GetValue(i)!)); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
388388
}
389389

390390
return ret;
@@ -1592,7 +1592,7 @@ public static void Sort<T>(T[] array, Comparison<T> comparison)
15921592
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
15931593
}
15941594

1595-
ArraySortHelper<T>.Sort(array!, 0, array!.Length, comparison); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
1595+
ArraySortHelper<T>.Sort(array!, 0, array!.Length, comparison!); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/538
15961596
}
15971597

15981598
public static bool TrueForAll<T>(T[] array, Predicate<T> match)

src/System.Private.CoreLib/shared/System/Attribute.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
using System.Diagnostics;
67
using System.Reflection;
78

@@ -15,7 +16,7 @@ public abstract partial class Attribute
1516
protected Attribute() { }
1617

1718
#if !CORERT
18-
public override bool Equals(object obj)
19+
public override bool Equals(object? obj)
1920
{
2021
if (obj == null)
2122
return false;
@@ -25,7 +26,7 @@ public override bool Equals(object obj)
2526

2627
Type thisType = this.GetType();
2728
object thisObj = this;
28-
object thisResult, thatResult;
29+
object? thisResult, thatResult;
2930

3031
while (thisType != typeof(Attribute))
3132
{
@@ -41,7 +42,7 @@ public override bool Equals(object obj)
4142
return false;
4243
}
4344
}
44-
thisType = thisType.BaseType;
45+
thisType = thisType.BaseType!;
4546
}
4647

4748
return true;
@@ -54,11 +55,11 @@ public override int GetHashCode()
5455
while (type != typeof(Attribute))
5556
{
5657
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
57-
object vThis = null;
58+
object? vThis = null;
5859

5960
for (int i = 0; i < fields.Length; i++)
6061
{
61-
object fieldValue = fields[i].GetValue(this);
62+
object? fieldValue = fields[i].GetValue(this);
6263

6364
// The hashcode of an array ignores the contents of the array, so it can produce
6465
// different hashcodes for arrays with the same contents.
@@ -74,15 +75,15 @@ public override int GetHashCode()
7475
if (vThis != null)
7576
return vThis.GetHashCode();
7677

77-
type = type.BaseType;
78+
type = type.BaseType!;
7879
}
7980

8081
return type.GetHashCode();
8182
}
8283
#endif
8384

8485
// Compares values of custom-attribute fields.
85-
private static bool AreFieldValuesEqual(object thisValue, object thatValue)
86+
private static bool AreFieldValuesEqual(object? thisValue, object? thatValue)
8687
{
8788
if (thisValue == null && thatValue == null)
8889
return true;
@@ -99,8 +100,8 @@ private static bool AreFieldValuesEqual(object thisValue, object thatValue)
99100
return false;
100101
}
101102

102-
Array thisValueArray = thisValue as Array;
103-
Array thatValueArray = thatValue as Array;
103+
Array thisValueArray = (Array)thisValue;
104+
Array thatValueArray = (Array)thatValue;
104105
if (thisValueArray.Length != thatValueArray.Length)
105106
{
106107
return false;
@@ -132,7 +133,7 @@ private static bool AreFieldValuesEqual(object thisValue, object thatValue)
132133

133134
public virtual object TypeId => GetType();
134135

135-
public virtual bool Match(object obj) => Equals(obj);
136+
public virtual bool Match(object? obj) => Equals(obj);
136137

137138
public virtual bool IsDefaultAttribute() => false;
138139
}

src/System.Private.CoreLib/shared/System/Collections/DictionaryEntry.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
using System.ComponentModel;
67

78
namespace System.Collections
@@ -13,11 +14,11 @@ namespace System.Collections
1314
public struct DictionaryEntry
1415
{
1516
private object _key; // Do not rename (binary serialization)
16-
private object _value; // Do not rename (binary serialization)
17+
private object? _value; // Do not rename (binary serialization)
1718

1819
// Constructs a new DictionaryEnumerator by setting the Key
1920
// and Value fields appropriately.
20-
public DictionaryEntry(object key, object value)
21+
public DictionaryEntry(object key, object? value)
2122
{
2223
_key = key;
2324
_value = value;
@@ -36,7 +37,7 @@ public object Key
3637
}
3738
}
3839

39-
public object Value
40+
public object? Value
4041
{
4142
get
4243
{
@@ -50,7 +51,7 @@ public object Value
5051
}
5152

5253
[EditorBrowsable(EditorBrowsableState.Never)]
53-
public void Deconstruct(out object key, out object value)
54+
public void Deconstruct(out object key, out object? value)
5455
{
5556
key = Key;
5657
value = Value;

src/System.Private.CoreLib/shared/System/Collections/Generic/ArraySortHelper.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
**
1414
===========================================================*/
1515

16+
#nullable enable
1617
using System.Diagnostics;
1718
using System.Runtime.CompilerServices;
1819

@@ -38,7 +39,7 @@ internal static int FloorLog2PlusOne(int n)
3839
return result;
3940
}
4041

41-
internal static void ThrowOrIgnoreBadComparer(object comparer)
42+
internal static void ThrowOrIgnoreBadComparer(object? comparer)
4243
{
4344
throw new ArgumentException(SR.Format(SR.Arg_BogusIComparer, comparer));
4445
}
@@ -48,7 +49,7 @@ internal partial class ArraySortHelper<T>
4849
{
4950
#region IArraySortHelper<T> Members
5051

51-
public void Sort(T[] keys, int index, int length, IComparer<T> comparer)
52+
public void Sort(T[] keys, int index, int length, IComparer<T>? comparer)
5253
{
5354
Debug.Assert(keys != null, "Check the arguments in the caller!");
5455
Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");
@@ -74,7 +75,7 @@ public void Sort(T[] keys, int index, int length, IComparer<T> comparer)
7475
}
7576
}
7677

77-
public int BinarySearch(T[] array, int index, int length, T value, IComparer<T> comparer)
78+
public int BinarySearch(T[] array, int index, int length, T value, IComparer<T>? comparer)
7879
{
7980
try
8081
{
@@ -335,7 +336,7 @@ internal partial class GenericArraySortHelper<T>
335336

336337
#region IArraySortHelper<T> Members
337338

338-
public void Sort(T[] keys, int index, int length, IComparer<T> comparer)
339+
public void Sort(T[] keys, int index, int length, IComparer<T>? comparer)
339340
{
340341
Debug.Assert(keys != null, "Check the arguments in the caller!");
341342
Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");
@@ -361,7 +362,7 @@ public void Sort(T[] keys, int index, int length, IComparer<T> comparer)
361362
}
362363
}
363364

364-
public int BinarySearch(T[] array, int index, int length, T value, IComparer<T> comparer)
365+
public int BinarySearch(T[] array, int index, int length, T value, IComparer<T>? comparer)
365366
{
366367
Debug.Assert(array != null, "Check the arguments in the caller!");
367368
Debug.Assert(index >= 0 && length >= 0 && (array.Length - index >= length), "Check the arguments in the caller!");
@@ -624,7 +625,7 @@ private static void InsertionSort(T[] keys, int lo, int hi)
624625

625626
internal partial class ArraySortHelper<TKey, TValue>
626627
{
627-
public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey> comparer)
628+
public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey>? comparer)
628629
{
629630
Debug.Assert(keys != null, "Check the arguments in the caller!"); // Precondition on interface method
630631
Debug.Assert(values != null, "Check the arguments in the caller!");
@@ -871,7 +872,7 @@ private static void InsertionSort(TKey[] keys, TValue[] values, int lo, int hi,
871872
internal partial class GenericArraySortHelper<TKey, TValue>
872873
where TKey : IComparable<TKey>
873874
{
874-
public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey> comparer)
875+
public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey>? comparer)
875876
{
876877
Debug.Assert(keys != null, "Check the arguments in the caller!");
877878
Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");

src/System.Private.CoreLib/shared/System/Collections/Generic/Comparer.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
using System.Runtime.CompilerServices;
67
using System.Runtime.Serialization;
78

@@ -21,9 +22,9 @@ public static Comparer<T> Create(Comparison<T> comparison)
2122
return new ComparisonComparer<T>(comparison);
2223
}
2324

24-
public abstract int Compare(T x, T y);
25+
public abstract int Compare(T x, T y); // TODO-NULLABLE-GENERIC: x and y must be marked as nullable
2526

26-
int IComparer.Compare(object x, object y)
27+
int IComparer.Compare(object? x, object? y)
2728
{
2829
if (x == null) return y == null ? 0 : -1;
2930
if (y == null) return 1;
@@ -58,7 +59,7 @@ public override int Compare(T x, T y)
5859
// Needs to be public to support binary serialization compatibility
5960
public sealed partial class GenericComparer<T> : Comparer<T> where T : IComparable<T>
6061
{
61-
public override int Compare(T x, T y)
62+
public override int Compare(T x, T y) // TODO-NULLABLE-GENERIC: x and y must be marked as nullable
6263
{
6364
if (x != null)
6465
{
@@ -70,7 +71,7 @@ public override int Compare(T x, T y)
7071
}
7172

7273
// Equals method for the comparer itself.
73-
public override bool Equals(object obj) =>
74+
public override bool Equals(object? obj) =>
7475
obj != null && GetType() == obj.GetType();
7576

7677
public override int GetHashCode() =>
@@ -94,7 +95,7 @@ public override int Compare(T? x, T? y)
9495
}
9596

9697
// Equals method for the comparer itself.
97-
public override bool Equals(object obj) =>
98+
public override bool Equals(object? obj) =>
9899
obj != null && GetType() == obj.GetType();
99100

100101
public override int GetHashCode() =>
@@ -106,13 +107,13 @@ public override int GetHashCode() =>
106107
// Needs to be public to support binary serialization compatibility
107108
public sealed partial class ObjectComparer<T> : Comparer<T>
108109
{
109-
public override int Compare(T x, T y)
110+
public override int Compare(T x, T y) // TODO-NULLABLE-GENERIC: x and y must be marked as nullable
110111
{
111112
return System.Collections.Comparer.Default.Compare(x, y);
112113
}
113114

114115
// Equals method for the comparer itself.
115-
public override bool Equals(object obj) =>
116+
public override bool Equals(object? obj) =>
116117
obj != null && GetType() == obj.GetType();
117118

118119
public override int GetHashCode() =>
@@ -130,7 +131,7 @@ private EnumComparer(SerializationInfo info, StreamingContext context) { }
130131
// public override int Compare(T x, T y) is runtime-specific
131132

132133
// Equals method for the comparer itself.
133-
public override bool Equals(object obj) =>
134+
public override bool Equals(object? obj) =>
134135
obj != null && GetType() == obj.GetType();
135136

136137
public override int GetHashCode() =>

0 commit comments

Comments
 (0)