From 607cca1431e5f5240b5337005b6715e5f90ba0a8 Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Thu, 24 Jun 2021 19:02:07 -0300 Subject: [PATCH 1/2] Allow null array to be implictly casted to Span --- BeefLibs/corlib/src/Span.bf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BeefLibs/corlib/src/Span.bf b/BeefLibs/corlib/src/Span.bf index 2b2f9c36..a2742aba 100644 --- a/BeefLibs/corlib/src/Span.bf +++ b/BeefLibs/corlib/src/Span.bf @@ -48,6 +48,9 @@ namespace System public static implicit operator Span (T[] array) { + if (array == null) + return default; + return Span(array); } From 36c72e794e56517f3779c482baf7fd5007f63d4f Mon Sep 17 00:00:00 2001 From: disarray2077 <86157825+disarray2077@users.noreply.github.com> Date: Thu, 24 Jun 2021 19:22:22 -0300 Subject: [PATCH 2/2] Actually, allow Spans to be created from null Arrays --- BeefLibs/corlib/src/Span.bf | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/BeefLibs/corlib/src/Span.bf b/BeefLibs/corlib/src/Span.bf index a2742aba..c632f6d2 100644 --- a/BeefLibs/corlib/src/Span.bf +++ b/BeefLibs/corlib/src/Span.bf @@ -16,18 +16,35 @@ namespace System public this(T[] array) { + if (array == null) + { + this = default; + return; + } mPtr = &array.[Friend]GetRef(0); mLength = array.[Friend]mLength; } public this(T[] array, int index) { + if (array == null) + { + Debug.Assert(index == 0); + this = default; + return; + } mPtr = &array[index]; mLength = array.[Friend]mLength - index; } public this(T[] array, int index, int length) { + if (array == null) + { + Debug.Assert(index == 0 && length == 0); + this = default; + return; + } if (length == 0) mPtr = null; else @@ -48,9 +65,6 @@ namespace System public static implicit operator Span (T[] array) { - if (array == null) - return default; - return Span(array); }