Fix Seq.empty rendering as "EmptyEnumerable" in serializers#19317
Fix Seq.empty rendering as "EmptyEnumerable" in serializers#19317T-Gro merged 5 commits intodotnet:mainfrom
Conversation
❗ Release notes requiredCaution 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:
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
|
901cdaf to
60f568f
Compare
|
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. |
…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
bdc35a9 to
a1522ec
Compare
|
@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. |
Summary
Fixes #17864
Seq.emptyused a custom DU typeEmptyEnumerable<'T>that serializers detected as an F# union, rendering"EmptyEnumerable"instead of[]Seq.emptyto delegate toSystem.Linq.Enumerable.Empty<'T>(), which returns a standard .NET typeSeq.concatoptimization from:? EmptyEnumerable<'T>to:? ICollection<'T> when Count = 0for broader empty collection detectionEmptyEnumerable<'T>type is kept unchanged for backward compatibilityTest plan
Seq.emptyis not a discriminated union type (FSharpType.IsUnionreturns false)Seq.concatwith empty elements still produces correct results