Skip to content

Commit

Permalink
Fix nullable annotations for ImmutableArray cast methods (dotnet#40084)
Browse files Browse the repository at this point in the history
* Fix nullable annotations for ImmutableArray cast methods,

Fixes dotnet#39799

* address feedback
  • Loading branch information
eiriktsarpalis authored Aug 3, 2020
1 parent f3b8255 commit f1911f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public partial struct ImmutableArray<T> : System.Collections.Generic.ICollection
public System.ReadOnlyMemory<T> AsMemory() { throw null; }
public System.ReadOnlySpan<T> AsSpan() { throw null; }
#endif
public System.Collections.Immutable.ImmutableArray<TOther> As<TOther>() where TOther : class { throw null; }
public System.Collections.Immutable.ImmutableArray<TOther> CastArray<TOther>() where TOther : class { throw null; }
public static System.Collections.Immutable.ImmutableArray<T> CastUp<TDerived>(System.Collections.Immutable.ImmutableArray<TDerived> items) where TDerived : class, T { throw null; }
public System.Collections.Immutable.ImmutableArray<TOther> As<TOther>() where TOther : class? { throw null; }
public System.Collections.Immutable.ImmutableArray<TOther> CastArray<TOther>() where TOther : class? { throw null; }
public static System.Collections.Immutable.ImmutableArray<T> CastUp<TDerived>(System.Collections.Immutable.ImmutableArray<TDerived> items) where TDerived : class?, T { throw null; }
public System.Collections.Immutable.ImmutableArray<T> Clear() { throw null; }
public bool Contains(T item) { throw null; }
public void CopyTo(int sourceIndex, T[] destination, int destinationIndex, int length) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public bool Equals(ImmutableArray<T> other)
/// <see cref="ImmutableArray{T}.As{TOther}"/> or <see cref="ImmutableArray{T}.CastArray{TOther}"/>method.
/// </remarks>
public static ImmutableArray<T> CastUp<TDerived>(ImmutableArray<TDerived> items)
where TDerived : class, T
where TDerived : class?, T
{
return new ImmutableArray<T>(items.array);
}
Expand All @@ -344,7 +344,7 @@ public static ImmutableArray<T> CastUp<TDerived>(ImmutableArray<TDerived> items)
/// array to an array of type <typeparam name="TOther"/>.
/// </summary>
/// <exception cref="InvalidCastException">Thrown if the cast is illegal.</exception>
public ImmutableArray<TOther> CastArray<TOther>() where TOther : class
public ImmutableArray<TOther> CastArray<TOther>() where TOther : class?
{
return new ImmutableArray<TOther>((TOther[])(object)array!);
}
Expand All @@ -364,9 +364,9 @@ public ImmutableArray<TOther> CastArray<TOther>() where TOther : class
/// element types to their derived types. However, downcasting is only successful
/// when it reverses a prior upcasting operation.
/// </remarks>
public ImmutableArray<TOther> As<TOther>() where TOther : class
public ImmutableArray<TOther> As<TOther>() where TOther : class?
{
return new ImmutableArray<TOther>((this.array as TOther[])!);
return new ImmutableArray<TOther>((this.array as TOther[]));
}

/// <summary>
Expand Down

0 comments on commit f1911f3

Please sign in to comment.