Merge pull request #799 from kebby/master
authorMarek Safar <marek.safar@gmail.com>
Tue, 12 Nov 2013 08:38:48 +0000 (00:38 -0800)
committerMarek Safar <marek.safar@gmail.com>
Tue, 12 Nov 2013 08:38:48 +0000 (00:38 -0800)
Task.WhenAllCore<T> now handles empty argument list correctly. Fixes #15956

mcs/class/corlib/System.Threading.Tasks/Task.cs
mcs/class/corlib/Test/System.Threading.Tasks/TaskTest.cs

index 1ae5559957ee710ce4206daf00fb0532f1df6987..5eefcb7da5f87592bc67d2751e579f0b95ed1055 100644 (file)
@@ -1082,6 +1082,9 @@ namespace System.Threading.Tasks
 
                internal static Task<TResult[]> WhenAllCore<TResult> (IList<Task<TResult>> tasks)
                {
+                       if (tasks.Count == 0)
+                               return FromResult(new TResult[0]);
+
                        foreach (var t in tasks) {
                                if (t == null)
                                        throw new ArgumentException ("tasks", "the tasks argument contains a null element");
index feff0e8b06f234afa871dfb8c18570b201ba566a..f61a64d4aa0f89fceb29833e418b9910cafabce2 100644 (file)
@@ -1149,6 +1149,16 @@ namespace MonoTests.System.Threading.Tasks
                        }
                }
 
+               [Test]
+               public void WhenAll_Empty ()
+               {
+                       var tasks = new Task[0];
+
+                       Task t = Task.WhenAll(tasks);
+
+                       Assert.IsTrue(t.Wait(1000), "#1");
+               }
+
                [Test]
                public void WhenAll_WithNull ()
                {
@@ -1274,6 +1284,18 @@ namespace MonoTests.System.Threading.Tasks
                        Assert.IsTrue (t.Wait (1000), "#2");
                }
 
+               [Test]
+               public void WhenAllResult_Empty ()
+               {
+                       var tasks = new Task<int>[0];
+
+                       Task<int[]> t = Task.WhenAll(tasks);
+
+                       Assert.IsTrue(t.Wait(1000), "#1");
+                       Assert.IsNotNull(t.Result, "#2");
+                       Assert.AreEqual(t.Result.Length, 0, "#3");
+               }
+
                [Test]
                public void WhenAllResult_WithNull ()
                {