-
Notifications
You must be signed in to change notification settings - Fork 144
add [fs-1141] Allow access modifiers to auto properties getters and setters #764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
RFCs/FS-1141-Allow-access-modifiers-to-auto-properties-getters-and-setters.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # F# RFC FS-1141 - Allow access modifiers to auto properties getters and setters | ||
|
|
||
| The design suggestion [Allow access modifies to auto properties getters and setters](https://github.com/fsharp/fslang-suggestions/issues/430) has been marked "approved in principle". | ||
|
|
||
| This RFC covers the detailed proposal for this suggestion. | ||
|
|
||
| - [x] [Suggestion](https://github.com/fsharp/fslang-suggestions/issues/430) | ||
| - [x] Approved in principle | ||
| - [x] [Implementation](https://github.com/dotnet/fsharp/pull/16687) | ||
| - [ ] Design Review Meeting(s) with @dsyme and others invitees | ||
| <!-- - [Discussion](https://github.com/fsharp/fslang-design/discussions/FILL-ME-IN) --> | ||
|
|
||
| # Summary | ||
|
|
||
| Allow access modifiers to auto properties getters and setters. | ||
|
|
||
| # Motivation | ||
|
|
||
| To simplify the syntax of defining a private-settable-read-only properties. | ||
|
|
||
| # Detailed design | ||
|
|
||
| Before this RFC, in a class type, the access modifier (`public`, `internal`, `private`) can only be placed before the property name. This RFC introduces the possibility of placing the access modifier before the getter and setter. | ||
|
|
||
| This will not work for abstract properties, because abstract members are not allowed to have access modifiers., | ||
|
|
||
| This will also not work within signature files, a property containing not the same access modifier should be written separately like: | ||
|
|
||
| ```fsharp | ||
| type MyClass = | ||
| member Property : int | ||
| member private Property : int with set | ||
| // the access modifier before getter and setter will be ignored | ||
| member Property2 : int with internal get, private set | ||
| ``` | ||
|
|
||
| The new syntax is: | ||
|
|
||
| ```fsharp | ||
| // Automatically implemented properties. | ||
| [ attributes ] | ||
| [ static ] member val [accessibility-modifier] PropertyName = initialization-expression [ with [accessibility-modifier] get, [accessibility-modifier] set ] | ||
| ``` | ||
|
|
||
| Like explicit property, the access modifier can only be placed before the one of two: | ||
|
|
||
| - The property name | ||
| - The getter or setter | ||
|
|
||
| When the access modifier is placed before the property name, it will be applied to both getter and setter; | ||
| When the access modifier is placed before the getter or setter, it will be applied to the corresponding getter or setter. | ||
|
|
||
| The access modifier cannot be placed before the property name and the getter or setter at the same time. | ||
|
|
||
| Example: | ||
|
|
||
| ```fsharp | ||
| type A() = | ||
| // allow, access modifier before property name | ||
| member val internal Allow1 = 0 with get, set | ||
| member val internal Allow2 = 0 with get | ||
| // allow, access modifier before getter or setter | ||
| member val Allow3 = 0 with public get, private set | ||
| member val Allow4 = 0 with public get, set | ||
| member val Allow5 = 0 with internal get | ||
| // not allowed, access modifier cannot be placed before the property name and the getter or setter at the same time | ||
| member val internal NotAllowed1 = 0 with public get, private set | ||
| member val internal NotAllowed2 = 0 with public get | ||
| ``` | ||
|
|
||
| # Drawbacks | ||
|
|
||
| > A more way to do same thing. | ||
|
|
||
| # Alternatives | ||
|
|
||
| What other designs have been considered? What is the impact of not doing this? | ||
|
|
||
| > Write an explicit property with getter and setter. | ||
|
|
||
| ```fsharp | ||
| type A() = | ||
| [<DefaultValue>] | ||
| val mutable private _B: int | ||
| member this.B with public get () = this._B and private set value = this._B <- value | ||
| ``` | ||
|
|
||
| # Compatibility | ||
|
|
||
| Please address all necessary compatibility questions: | ||
|
|
||
| * Is this a breaking change? | ||
|
|
||
| > No | ||
|
|
||
| * What happens when previous versions of the F# compiler encounter this design addition as source code? | ||
|
|
||
| > Build error | ||
|
|
||
| * What happens when previous versions of the F# compiler encounter this design addition in compiled binaries? | ||
|
|
||
| > Unchanged, as explicit property works. | ||
|
|
||
| * If this is a change or extension to FSharp.Core, what happens when previous versions of the F# compiler encounter this construct? | ||
|
|
||
| # Pragmatics | ||
|
|
||
| ## Diagnostics | ||
|
|
||
| Please list the reasonable expectations for diagnostics for misuse of this feature. | ||
|
|
||
| ## Tooling | ||
|
|
||
| Please list the reasonable expectations for tooling for this feature, including any of these: | ||
|
|
||
| * Debugging | ||
| * Breakpoints/stepping | ||
| * Expression evaluator | ||
| * Data displays for locals and hover tips | ||
| * Auto-complete | ||
| * Tooltips | ||
| * Navigation and Go To Definition | ||
| * Colorization | ||
| * Brace/parenthesis matching | ||
|
|
||
| ## Performance | ||
|
|
||
| Please list any notable concerns for impact on the performance of compilation and/or generated code | ||
|
|
||
| * For existing code | ||
| * For the new features | ||
|
|
||
| ## Scaling | ||
|
|
||
| Please list the dimensions that describe the inputs for this new feature, e.g. "number of widgets" etc. For each, estimate a reasonable upper bound for the expected size in human-written code and machine-generated code that the compiler will accept. | ||
|
|
||
| For example | ||
|
|
||
| * Expected maximum number of widgets in reasonable hand-written code: 100 | ||
| * Expected reasonable upper bound for number of widgets accepted: 500 | ||
|
|
||
| Testing should particularly check that compilation is linear (or log-linear or similar) along these dimensions. If quadratic or worse this should ideally be noted in the RFC. | ||
|
|
||
| ## Culture-aware formatting/parsing | ||
|
|
||
| Does the proposed RFC interact with culture-aware formatting and parsing of numbers, dates and currencies? For example, if the RFC includes plaintext outputs, are these outputs specified to be culture-invariant or current-culture. | ||
|
|
||
| # Unresolved questions | ||
|
|
||
| What parts of the design are still TBD? | ||
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.
Uh oh!
There was an error while loading. Please reload this page.