diff --git a/src/libraries/System.Linq/src/System/Linq/Select.cs b/src/libraries/System.Linq/src/System/Linq/Select.cs index 79700032a69d7a..db9adc98740304 100644 --- a/src/libraries/System.Linq/src/System/Linq/Select.cs +++ b/src/libraries/System.Linq/src/System/Linq/Select.cs @@ -60,7 +60,7 @@ private static IEnumerable SelectImplementation(Func< // for value types. We don't do the same for reference types because reference type // expansion can happen lazily at runtime and the AOT compiler does postpone it (we // don't need more code, just more data structures describing the new types). - if (/*ValueTypeTrimFriendlySelect &&*/ typeof(TResult).IsValueType) + if (ValueTypeTrimFriendlySelect && typeof(TResult).IsValueType) { #if OPTIMIZE_FOR_SIZE return new IEnumerableSelectIterator(iterator, selector); diff --git a/src/libraries/System.Linq/tests/SkipWhileTests.cs b/src/libraries/System.Linq/tests/SkipWhileTests.cs index a13a686cef3f34..198f105a884d9e 100644 --- a/src/libraries/System.Linq/tests/SkipWhileTests.cs +++ b/src/libraries/System.Linq/tests/SkipWhileTests.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using Microsoft.DotNet.RemoteExecutor; using Xunit; namespace System.Linq.Tests @@ -62,14 +63,33 @@ public void RunOnce() Assert.Equal(Enumerable.Range(10, 10), Enumerable.Range(0, 20).RunOnce().SkipWhile((i, idx) => idx < 10)); } + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public static void SkipErrorWhenSourceErrors_TrimFriendlySelectTrue() + { + RemoteExecutor.Invoke(() => + { + AppContext.SetSwitch("System.Linq.Enumerable.ValueTypeTrimFriendlySelect", true); + + var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4); + var valuesFromEnumerable = source.ToList(); + List expectedValues = [(decimal)1/2]; + Assert.Equal(expectedValues, valuesFromEnumerable); + }).Dispose(); + } + [Fact] - public void SkipErrorWhenSourceErrors() + public void SkipErrorWhenSourceErrors_TrimFriendlySelectFalse() { - var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4); - using(var en = source.GetEnumerator()) + RemoteExecutor.Invoke(() => { - Assert.Throws(() => en.MoveNext()); - } + AppContext.SetSwitch("System.Linq.Enumerable.ValueTypeTrimFriendlySelect", false); + + var source = NumberRangeGuaranteedNotCollectionType(-2, 5).Select(i => (decimal)i).Select(m => 1 / m).Skip(4); + using (var en = source.GetEnumerator()) + { + Assert.Throws(() => en.MoveNext()); + } + }).Dispose(); } [Fact] diff --git a/src/libraries/System.Linq/tests/System.Linq.Tests.csproj b/src/libraries/System.Linq/tests/System.Linq.Tests.csproj index 1e4692999a1743..ac0ef5e696463e 100644 --- a/src/libraries/System.Linq/tests/System.Linq.Tests.csproj +++ b/src/libraries/System.Linq/tests/System.Linq.Tests.csproj @@ -1,5 +1,6 @@ + true $(NetCoreAppCurrent) true