diff --git a/eng/Versions.props b/eng/Versions.props index b1ba6a0dfb62b..0b398500e1356 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -18,8 +18,7 @@ true true false - - + 3.7.0-2.20258.1 dotnet diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs index f4e007424b5e9..1939dd9d68b29 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs @@ -756,13 +756,10 @@ private bool TryTakeWithNoTimeValidation([MaybeNullWhen(false)] out T item, int } } - if (waitForSemaphoreWasSuccessful) - { - Debug.Assert(item != null); - } - #pragma warning disable CS8762 - // Compiler can't automatically deduce 'item' has a non-null value when returning false. + // https://github.com/dotnet/runtime/issues/36132 + // Compiler can't automatically deduce that nullability constraints + // for 'item' are satisfied at this exit point. return waitForSemaphoreWasSuccessful; #pragma warning restore CS8762 } diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs index 5ccc784f54dfa..3088224b47186 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs @@ -220,8 +220,9 @@ private bool TrySteal([MaybeNullWhen(false)] out T result, bool take) if (gotItem) { #pragma warning disable CS8762 - // Compiler can't automatically deduce that 'result' is set to a valid value - // (which may be null if T allows it) at this exit point. + // https://github.com/dotnet/runtime/issues/36132 + // Compiler can't automatically deduce that nullability constraints + // for 'result' are satisfied at this exit point. return true; #pragma warning restore CS8762 } diff --git a/src/libraries/System.Collections.Concurrent/tests/BlockingCollectionTests.cs b/src/libraries/System.Collections.Concurrent/tests/BlockingCollectionTests.cs index 6f8a107ccb8c6..9a21bc6ef01e7 100644 --- a/src/libraries/System.Collections.Concurrent/tests/BlockingCollectionTests.cs +++ b/src/libraries/System.Collections.Concurrent/tests/BlockingCollectionTests.cs @@ -966,6 +966,22 @@ public static void Test21_CopyToExceptions() }); } + [Fact] + public static void Test_WithNullEntries() + { + BlockingCollection collection = new BlockingCollection() + { + "hello", + null, + "goodbye" + }; + + Assert.Equal("hello", collection.Take()); + Assert.Null(collection.Take()); + Assert.Equal("goodbye", collection.Take()); + Assert.False(collection.TryTake(out _)); + } + [Fact] public static void Test_LargeSize() {