Skip to content

Fix Seq.empty rendering as "EmptyEnumerable" in serializers#19317

Merged
T-Gro merged 5 commits intodotnet:mainfrom
apoorvdarshan:fix-seq-empty-serialization
Mar 4, 2026
Merged

Fix Seq.empty rendering as "EmptyEnumerable" in serializers#19317
T-Gro merged 5 commits intodotnet:mainfrom
apoorvdarshan:fix-seq-empty-serialization

Conversation

@apoorvdarshan
Copy link
Contributor

Summary

Fixes #17864

  • Seq.empty used a custom DU type EmptyEnumerable<'T> that serializers detected as an F# union, rendering "EmptyEnumerable" instead of []
  • Changed Seq.empty to delegate to System.Linq.Enumerable.Empty<'T>(), which returns a standard .NET type
  • Updated Seq.concat optimization from :? EmptyEnumerable<'T> to :? ICollection<'T> when Count = 0 for broader empty collection detection
  • EmptyEnumerable<'T> type is kept unchanged for backward compatibility

Test plan

  • Added test verifying Seq.empty is not a discriminated union type (FSharpType.IsUnion returns false)
  • Added test verifying Seq.concat with empty elements still produces correct results
  • All 147 existing Seq module tests pass

@github-actions
Copy link
Contributor

github-actions bot commented Feb 17, 2026

❗ Release notes required

@apoorvdarshan,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

You can open this PR in browser to add release notes: open in github.dev

Change path Release notes path Description
src/FSharp.Core docs/release-notes/.FSharp.Core/11.0.100.md No release notes found or release notes format is not correct

@apoorvdarshan apoorvdarshan force-pushed the fix-seq-empty-serialization branch from 901cdaf to 60f568f Compare February 17, 2026 21:05
@T-Gro
Copy link
Member

T-Gro commented Feb 18, 2026

Please see #19322 (comment) .

I think both are attempting the same thing, but we need to be a lot more cautious and pro-active in detecting breaking changes.
We can decide to accept some of these breaks, but we have to know them and document them.

…7864)

Seq.empty used a custom DU type EmptyEnumerable<'T> that serializers
detected as an F# union, rendering "EmptyEnumerable" instead of [].

- Change Seq.empty to delegate to System.Linq.Enumerable.Empty<'T>()
- Update concat optimization from :? EmptyEnumerable<'T> to
  :? ICollection<'T> when Count = 0 for broader empty detection
- Add tests verifying Seq.empty is not a DU type and concat still works
@apoorvdarshan apoorvdarshan force-pushed the fix-seq-empty-serialization branch from bdc35a9 to a1522ec Compare February 18, 2026 16:32
@apoorvdarshan
Copy link
Contributor Author

@T-Gro Thanks for the feedback. Unlike #19322, this PR keeps the EmptyEnumerable type unchanged for backward compat — only the Seq.empty binding and the concat optimization are updated. Happy to target this for .NET 11 instead and add cross-compat test coverage for the equality/versioning scenarios you mentioned.

@github-project-automation github-project-automation bot moved this from New to In Progress in F# Compiler and Tooling Mar 2, 2026
@T-Gro T-Gro enabled auto-merge (squash) March 2, 2026 16:31
@T-Gro T-Gro merged commit 6479611 into dotnet:main Mar 4, 2026
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Seq.empty renders as "EmptyEnumerable"

2 participants