Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/System.Private.CoreLib/shared/System/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ int IStructuralEquatable.GetHashCode(IEqualityComparer comparer)

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

return ret;
Expand Down Expand Up @@ -1552,7 +1552,7 @@ public static void Sort<T>(T[] array, Comparison<T> comparison)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison);
}

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

public static bool TrueForAll<T>(T[] array, Predicate<T> match)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.ComponentModel;

namespace System.Collections
Expand All @@ -13,11 +14,11 @@ namespace System.Collections
public struct DictionaryEntry
{
private object _key; // Do not rename (binary serialization)
private object _value; // Do not rename (binary serialization)
private object? _value; // Do not rename (binary serialization)

// Constructs a new DictionaryEnumerator by setting the Key
// and Value fields appropriately.
public DictionaryEntry(object key, object value)
public DictionaryEntry(object key, object? value)
{
_key = key;
_value = value;
Expand All @@ -36,7 +37,7 @@ public object Key
}
}

public object Value
public object? Value
{
get
{
Expand All @@ -50,7 +51,7 @@ public object Value
}

[EditorBrowsable(EditorBrowsableState.Never)]
public void Deconstruct(out object key, out object value)
public void Deconstruct(out object key, out object? value)
{
key = Key;
value = Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
**
===========================================================*/

#nullable enable
using System.Diagnostics;
using System.Runtime.CompilerServices;

Expand All @@ -38,7 +39,7 @@ internal static int FloorLog2PlusOne(int n)
return result;
}

internal static void ThrowOrIgnoreBadComparer(object comparer)
internal static void ThrowOrIgnoreBadComparer(object? comparer)
{
throw new ArgumentException(SR.Format(SR.Arg_BogusIComparer, comparer));
}
Expand All @@ -48,7 +49,7 @@ internal partial class ArraySortHelper<T>
{
#region IArraySortHelper<T> Members

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

public int BinarySearch(T[] array, int index, int length, T value, IComparer<T> comparer)
public int BinarySearch(T[] array, int index, int length, T value, IComparer<T>? comparer)
{
try
{
Expand Down Expand Up @@ -335,7 +336,7 @@ internal partial class GenericArraySortHelper<T>

#region IArraySortHelper<T> Members

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

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

internal partial class ArraySortHelper<TKey, TValue>
{
public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey> comparer)
public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey>? comparer)
{
Debug.Assert(keys != null, "Check the arguments in the caller!"); // Precondition on interface method
Debug.Assert(values != null, "Check the arguments in the caller!");
Expand Down Expand Up @@ -871,7 +872,7 @@ private static void InsertionSort(TKey[] keys, TValue[] values, int lo, int hi,
internal partial class GenericArraySortHelper<TKey, TValue>
where TKey : IComparable<TKey>
{
public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey> comparer)
public void Sort(TKey[] keys, TValue[] values, int index, int length, IComparer<TKey>? comparer)
{
Debug.Assert(keys != null, "Check the arguments in the caller!");
Debug.Assert(index >= 0 && length >= 0 && (keys.Length - index >= length), "Check the arguments in the caller!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

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

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

int IComparer.Compare(object x, object y)
int IComparer.Compare(object? x, object? y)
{
if (x == null) return y == null ? 0 : -1;
if (y == null) return 1;
Expand Down Expand Up @@ -58,7 +59,7 @@ public override int Compare(T x, T y)
// Needs to be public to support binary serialization compatibility
public sealed partial class GenericComparer<T> : Comparer<T> where T : IComparable<T>
{
public override int Compare(T x, T y)
public override int Compare(T x, T y) // TODO-NULLABLE-GENERIC: x and y must be marked as nullable
{
if (x != null)
{
Expand All @@ -70,7 +71,7 @@ public override int Compare(T x, T y)
}

// Equals method for the comparer itself.
public override bool Equals(object obj) =>
public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();

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

// Equals method for the comparer itself.
public override bool Equals(object obj) =>
public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();

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

// Equals method for the comparer itself.
public override bool Equals(object obj) =>
public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();

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

// Equals method for the comparer itself.
public override bool Equals(object obj) =>
public override bool Equals(object? obj) =>
obj != null && GetType() == obj.GetType();

public override int GetHashCode() =>
Expand Down
Loading