Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6479611

Browse files
Fix Seq.empty rendering as "EmptyEnumerable" in serializers (#19317)
1 parent 761162d commit 6479611

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

docs/release-notes/.FSharp.Core/10.0.300.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Fix tuple/multi-value projections in queries to use Queryable.Select instead of Enumerable.Select when the source is IQueryable, preserving query composition and enabling async operations like ToListAsync() in Entity Framework Core. ([Issue #3782](https://github.com/dotnet/fsharp/issues/3782), [Issue #15133](https://github.com/dotnet/fsharp/issues/15133))
88
* Fix EvaluateQuotation to handle Sequential expressions, void method calls (unit return), and other patterns that were previously throwing NotSupportedException. Also properly handles unit-returning expressions by using Action delegates instead of Func delegates. ([Issue #19099](https://github.com/dotnet/fsharp/issues/19099))
99
* Fix query conditionals without else branch (if-then only) that were causing type mismatch errors. Now properly extracts element type from IQueryable for creating empty sequences. ([Issue #3445](https://github.com/dotnet/fsharp/issues/3445))
10-
* Ensure culture-independent parsing of .NET-style interpolated string holes. ([Issue #19367](https://github.com/dotnet/fsharp/issues/19367), [PR #19370](https://github.com/dotnet/fsharp/pull/19370))
10+
* Fix `Seq.empty` rendering as `"EmptyEnumerable"` in serializers by delegating to `System.Linq.Enumerable.Empty<'T>()` instead of using a custom DU type. ([Issue #17864](https://github.com/dotnet/fsharp/issues/17864), [PR #19317](https://github.com/dotnet/fsharp/pull/19317))
1111

1212
### Added
1313

src/FSharp.Core/seq.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ module Seq =
608608
mkUnfoldSeq generator state
609609

610610
[<CompiledName("Empty")>]
611-
let empty<'T> = (EmptyEnumerable :> seq<'T>)
611+
let empty<'T> = System.Linq.Enumerable.Empty<'T>()
612612

613613
[<CompiledName("InitializeInfinite")>]
614614
let initInfinite initializer =

src/FSharp.Core/seqcore.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ module RuntimeHelpers =
313313
let rec takeOuter() =
314314
if outerEnum.MoveNext() then
315315
let ie = outerEnum.Current
316-
// Optimization to detect the statically-allocated empty IEnumerables
316+
// Optimization to detect empty IEnumerables without calling GetEnumerator
317317
match box ie with
318-
| :? EmptyEnumerable<'T> ->
318+
| :? ICollection<'T> as c when c.Count = 0 ->
319319
// This one is empty, just skip, don't call GetEnumerator, try again
320320
takeOuter()
321321
| _ ->

tests/AheadOfTime/Trimming/check.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ function CheckTrim($root, $tfm, $outputfile, $expected_len, $callerLineNumber) {
6363
$allErrors = @()
6464

6565
# Check net9.0 trimmed assemblies
66-
$allErrors += CheckTrim -root "SelfContained_Trimming_Test" -tfm "net9.0" -outputfile "FSharp.Core.dll" -expected_len 311296 -callerLineNumber 66
66+
$allErrors += CheckTrim -root "SelfContained_Trimming_Test" -tfm "net9.0" -outputfile "FSharp.Core.dll" -expected_len 310784 -callerLineNumber 66
6767

6868
# Check net9.0 trimmed assemblies with static linked FSharpCore
69-
$allErrors += CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net9.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 9169408 -callerLineNumber 69
69+
$allErrors += CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net9.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 9168384 -callerLineNumber 69
7070

7171
# Check net9.0 trimmed assemblies with F# metadata resources removed
7272
$allErrors += CheckTrim -root "FSharpMetadataResource_Trimming_Test" -tfm "net9.0" -outputfile "FSharpMetadataResource_Trimming_Test.dll" -expected_len 7609344 -callerLineNumber 72

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,4 +1523,17 @@ type SeqModule() =
15231523

15241524
let choice = seq |> Seq.randomSampleBy (fun () -> 1.0) 0
15251525

1526-
Assert.AreEqual(0, choice |> Seq.length)
1526+
Assert.AreEqual(0, choice |> Seq.length)
1527+
1528+
[<Fact>]
1529+
member _.``Seq.empty is not a discriminated union type``() =
1530+
let empty = Seq.empty<int>
1531+
let ty = empty.GetType()
1532+
let isUnion = Microsoft.FSharp.Reflection.FSharpType.IsUnion(ty)
1533+
Assert.False(isUnion, "Seq.empty should not be a discriminated union type")
1534+
1535+
[<Fact>]
1536+
member _.``Seq.concat with empty elements works``() =
1537+
let result = Seq.concat [ Seq.empty; seq { 1; 2 }; Seq.empty; seq { 3 }; Seq.empty ]
1538+
let expected = [| 1; 2; 3 |]
1539+
Assert.AreEqual(expected, result |> Seq.toArray)

0 commit comments

Comments
 (0)