Sfoglia il codice sorgente

Fix for NullReferenceException in SelectMany.

Bart De Smet 10 anni fa
parent
commit
3497cd5b6d

+ 2 - 4
Ix.NET/Source/System.Interactive.Async/AsyncEnumerable.Single.cs

@@ -252,12 +252,11 @@ namespace System.Linq
 
 
                 var disposeIe = new Action(() =>
                 var disposeIe = new Action(() =>
                 {
                 {
-                    IAsyncEnumerator<TResult> localIe;
+                    var localIe = default(IAsyncEnumerator<TResult>);
 
 
                     lock (syncRoot)
                     lock (syncRoot)
                     {
                     {
                         localIe = ie;
                         localIe = ie;
-                        ie = null;
                     }
                     }
 
 
                     if (localIe != null)
                     if (localIe != null)
@@ -346,12 +345,11 @@ namespace System.Linq
 
 
                 var disposeIe = new Action(() =>
                 var disposeIe = new Action(() =>
                 {
                 {
-                    IAsyncEnumerator<TResult> localIe;
+                    var localIe = default(IAsyncEnumerator<TResult>);
 
 
                     lock (syncRoot)
                     lock (syncRoot)
                     {
                     {
                         localIe = ie;
                         localIe = ie;
-                        ie = null;
                     }
                     }
 
 
                     if (localIe != null)
                     if (localIe != null)

+ 12 - 0
Ix.NET/Source/Tests/AsyncTests.Bugs.cs

@@ -207,6 +207,18 @@ namespace Tests
             evt.WaitOne();
             evt.WaitOne();
             yield return 42;
             yield return 42;
         }
         }
+
+        [TestMethod]
+        public void TakeOneFromSelectMany()
+        {
+            var enumerable = AsyncEnumerable
+                .Return(0)
+                .SelectMany(_ => AsyncEnumerable.Return("Check"))
+                .Take(1)
+                .Do(_ => { });
+
+            Assert.AreEqual("Check", enumerable.First().Result);
+        }
     }
     }
 
 
     static class MyExt
     static class MyExt