Repository navigation
Convert nullary union cases to static property reads in LINQ trees - #21007
Open
pcshrosbree wants to merge 2 commits into
Open
pcshrosbree wants to merge 2 commits into
pcshrosbree wants to merge 2 commits into
Conversation
…nConverter `LeafExpressionConverter` converted every union case construction to a call of the method that `FSharpValue.PreComputeUnionConstructorInfo` returns. For a nullary case with a static property, that method is the property's getter, so `Kind.Handle` became `Expression.Call(get_Handle)` and printed as `Kind.get_Handle()`. C# produces `Expression.Property(null, Handle)` for the same member, which is the shape LINQ providers and tree printers expect for a static property. Use the property when the getter belongs to one. The compiler emits that property for nullary cases of reference, struct and generic unions, and for `[]`. Nullary cases of unions marked with `UseNullAsTrueValue`, including `None`, keep the call: F# LINQ providers recognise `None` by matching `get_None()`, and its value is null either way. A case whose getter has no corresponding static property keeps the call too; `[<DefaultAugmentation(false)>]` can cause that.
Contributor
✅ Release notes checked
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
LeafExpressionConverternow converts a nullary union case such asKind.Handleto a read of its static property,Expression.Property(null, Handle), which is what C# produces for the same member. Until now it producedExpression.Call(null, get_Handle), which prints asKind.get_Handle(). Code that looks for static members asMemberExpression, or prints a tree back as C#, saw a call to an accessor instead, and C# does not accept an explicit accessor call (CS0571). The compiler emits the static property for nullary cases of reference, struct and generic unions and for[]. The converted tree evaluates to the same value as before. I found this while testing LINQ providers.Two kinds of case keep the call:
UseNullAsTrueValue, such asNone. F# LINQ providers recogniseNoneby matchingget_None()(SQLProvider'sOptionNonepattern, for example), and its value is null either way.[<DefaultAugmentation(false)>]can cause.The new tests cover the property reads and both kinds of case that keep the call.
Checklist
Note
Prepared with AI assistance (Anthropic Claude, OpenAI Codex). I reviewed it before posting.