RFC FS-1353 - Parameterless struct constructors and struct initializers - #855
Open
xperiandri wants to merge 2 commits into
Open
xperiandri wants to merge 2 commits into
xperiandri wants to merge 2 commits into
Conversation
Covers fslang-suggestions fsharp#362 and #1056, both approved in principle, for parity with C# 10 parameterless struct constructors and struct field initializers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
Author
|
If it makes sens to describe only the difference with classes that may be shorter |
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.
Click “Files changed” → “⋯” → “View file” for the rendered RFC.
Summary
F# struct types can declare a public parameterless constructor (
new() = ...ortype S() = ...). Structs with a primary constructor can contain instancelet,doandmember valdefinitions, the F# counterpart of C# 10 struct field initializers.S()calls a public parameterless constructor and otherwise zero-initializes, as in C#. For a struct with such initializers,S()never zero-initializes;Unchecked.defaultof<S>still does. Non-public parameterless constructors of imported structs are ignored, as in C#. Gated by a preview feature; no FSharp.Core change.Both suggestions are approved in principle: #362 (parameterless constructors in structs) and #1056 (
dobindings in structs).Current behaviour the RFC starts from
F# column checked with SDK 11.0.100-rc.1; C# column from the C# 10 proposal, with
new S()and CS8958 checked on the same SDK.new() = .../type S() =in a structpublic(CS8958)let/do/member valin a primary-constructor structS()on a C# struct withpublic S()S()on an IL struct with aprivateorinternalparameterless constructornew 'T()for that IL structMissingMethodExceptionat run timeUnchecked.defaultof,Array.zeroCreate,[<DefaultValue>]field, omitted[<Optional>]argument<@ S() @>NewObjectwith a constructor,DefaultValuewithoutRelated
🤖 Generated with Claude Code