dotnet / dotnet/reactive

System.Linq.AsyncEnumerable.SkipLast() throws an exception

Open
#1,783 1 comment 2 reactions 0 assignees View on GitHub
[area] Ix
Dominant language
C#
Stars
7.2k
Forks
798
PR merge metrics
No merged PRs in 30d

Description

#### Bug

Despite our best efforts, bugs can slip into releases or corner cases forgotten about. We will try our best to remedy the situation
and/or provide workarounds. Note that certain (odd) behaviors are by design and as such are not considered bugs.

> Which subcomponent library (Ix, Async.Ix)?
System.Linq.Async

> Which library version?
6.0.1

> What are the platform(s), environment(s) and related component version(s)?
All

> What is the use case or problem?
Calling `.SkipLast()` with a zero or negative number with a non-collection async enumerable will throw an exception.

> What is the expected outcome?
A list of two items (5, 6). Same behavior as `await AsyncEnumerable.Range(5,2).SkipLast(-4).ToListAsync()`

> What is the actual outcome?
An exception: `InvalidOperationException` (Queue empty)`

> What is the stacktrace of the exception(s) if any?
```
at System.Collections.Generic.Queue`1.ThrowForEmptyQueue()
at System.Collections.Generic.Queue`1.Dequeue()
at System.Linq.AsyncEnumerable.g__Core|343_0[TSource](IAsyncEnumerable`1 source, Int32 count, CancellationToken cancellationToken)+MoveNext() in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs:line 54
at System.Linq.AsyncEnumerable.g__Core|343_0[TSource](IAsyncEnumerable`1 source, Int32 count, CancellationToken cancellationToken)+MoveNext() in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SkipLast.cs:line 52
at System.Linq.AsyncEnumerable.g__Core|343_0[TSource](IAsyncEnumerable`1 source, Int32 count, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource.GetResult()
at System.Linq.AsyncEnumerable.g__Core|424_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToList.cs:line 36
at System.Linq.AsyncEnumerable.g__Core|424_0[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/ToList.cs:line 36
```

> Do you have a code snippet or project that reproduces the problem?
Code to trigger error:
```csharp
var list = await Test().SkipLast(-4).ToListAsync();

async IAsyncEnumerable Test()
{
yield return 5;
yield return 6;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.