This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding null check for implicit cast from array to Span. (#25257)
* Adding null check for implicit cast from array to Span. * Addressing PR feedback - adding check for ArraySegment
- Loading branch information
Showing
5 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/System.Memory/tests/ReadOnlySpan/ImplicitConversion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Xunit; | ||
|
||
namespace System.SpanTests | ||
{ | ||
public static partial class ReadOnlySpanTests | ||
{ | ||
[Fact] | ||
public static void NullImplicitCast() | ||
{ | ||
int[] dst = null; | ||
ReadOnlySpan<int> srcSpan = dst; | ||
Assert.True(ReadOnlySpan<int>.Empty == srcSpan); | ||
} | ||
|
||
[Fact] | ||
public static void ArraySegmentDefaultImplicitCast() | ||
{ | ||
ArraySegment<int> dst = default; | ||
ReadOnlySpan<int> srcSpan = dst; | ||
Assert.True(ReadOnlySpan<int>.Empty == srcSpan); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Xunit; | ||
|
||
namespace System.SpanTests | ||
{ | ||
public static partial class SpanTests | ||
{ | ||
[Fact] | ||
public static void NullImplicitCast() | ||
{ | ||
int[] dst = null; | ||
Span<int> srcSpan = dst; | ||
Assert.True(Span<int>.Empty == srcSpan); | ||
} | ||
|
||
[Fact] | ||
public static void ArraySegmentDefaultImplicitCast() | ||
{ | ||
ArraySegment<int> dst = default; | ||
Span<int> srcSpan = dst; | ||
Assert.True(Span<int>.Empty == srcSpan); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters