Skip to content

Commit 4e1f030

Browse files
Fix bug in SkipLast(0) for custom sequence (try to dequeue from empty queue)
1 parent 85f1eb7 commit 4e1f030

File tree

2 files changed

+6
-4
lines changed
  • Ix.NET/Source

2 files changed

+6
-4
lines changed

Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/SkipLast.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT License.
3-
// See the LICENSE file in the project root for more information.
3+
// See the LICENSE file in the project root for more information.
44

55
using System;
66
using System.Collections.Generic;
@@ -64,12 +64,13 @@ public async Task SkipLast_Zero()
6464
}
6565

6666
[Fact]
67-
public void SkipLast_Zero_NoAlias()
67+
public async Task SkipLast_Zero_NoAlias()
6868
{
6969
var xs = Xs();
7070
var ys = xs.SkipLast(0);
7171

7272
Assert.NotSame(xs, ys);
73+
await NoNextAsync(ys.GetAsyncEnumerator());
7374
}
7475

7576
private async IAsyncEnumerable<int> Xs()

Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT License.
3-
// See the LICENSE file in the project root for more information.
3+
// See the LICENSE file in the project root for more information.
44

55
using System.Collections.Generic;
66
using System.Diagnostics;
@@ -55,7 +55,8 @@ static async IAsyncEnumerable<TSource> Core(IAsyncEnumerable<TSource> source, in
5555
{
5656
do
5757
{
58-
yield return queue.Dequeue();
58+
if (queue.Count > 0)
59+
yield return queue.Dequeue();
5960
queue.Enqueue(e.Current);
6061
}
6162
while (await e.MoveNextAsync());

0 commit comments

Comments
 (0)