diff --git a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/OfType.cs b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/OfType.cs index 1f3fdd457c..1fbcf2d0c0 100644 --- a/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/OfType.cs +++ b/Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/OfType.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. -// See the LICENSE file in the project root for more information. +// See the LICENSE file in the project root for more information. using System; using System.Linq; @@ -40,5 +40,17 @@ public async Task OfType_String() await HasNextAsync(e, "foo"); await NoNextAsync(e); } + + [Fact] + public async Task OfType_NotNullObject() + { + var xs = new object?[] { 42, null, "foo", null }.ToAsyncEnumerable(); + var ys = xs.OfType(); + + var e = ys.GetAsyncEnumerator(); + await HasNextAsync(e, 42); + await HasNextAsync(e, "foo"); + await NoNextAsync(e); + } } } diff --git a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OfType.cs b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OfType.cs index df31bebdb3..b9e2bb476a 100644 --- a/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OfType.cs +++ b/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/OfType.cs @@ -1,6 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. -// See the LICENSE file in the project root for more information. +// See the LICENSE file in the project root for more information. using System.Collections.Generic; using System.Threading; @@ -25,14 +25,14 @@ public static partial class AsyncEnumerable /// The async-enumerable sequence that contains the elements to be filtered. /// An async-enumerable sequence that contains elements from the input sequence of type TResult. /// is null. - public static IAsyncEnumerable OfType(this IAsyncEnumerable source) + public static IAsyncEnumerable OfType(this IAsyncEnumerable source) { if (source == null) throw Error.ArgumentNull(nameof(source)); return Core(source); - static async IAsyncEnumerable Core(IAsyncEnumerable source, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default) + static async IAsyncEnumerable Core(IAsyncEnumerable source, [System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken = default) { await foreach (var obj in source.WithCancellation(cancellationToken).ConfigureAwait(false)) {