Skip to content

Comments

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

Open
apoorvdarshan wants to merge 3 commits intodotnet:mainfrom
apoorvdarshan:fix-seq-empty-serialization
Open

Fix Seq.empty rendering as "EmptyEnumerable" in serializers#19317
apoorvdarshan wants to merge 3 commits intodotnet:mainfrom
apoorvdarshan:fix-seq-empty-serialization

Conversation

@apoorvdarshan
Copy link

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


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/FSharp.Core docs/release-notes/.FSharp.Core/10.0.300.md

@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
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Seq.empty renders as "EmptyEnumerable"

2 participants