Skip to content

Allow access modifiers to auto properties getters and setters - #16687

Merged
psfinaki merged 22 commits into
dotnet:mainfrom
ijklam:access-modifies-to-auto-properties
Mar 7, 2024
Merged

Allow access modifiers to auto properties getters and setters#16687
psfinaki merged 22 commits into
dotnet:mainfrom
ijklam:access-modifies-to-auto-properties

Conversation

@ijklam

@ijklamijklam commented Feb 10, 2024

Copy link
Copy Markdown
Contributor

Description

Implements this suggestion

图片

Checklist

  • RFC added

  • Put it under preview flag

  • Test cases added

  • Performance benchmarks added in case of performance changes

  • Release notes entry updated:

    Please make sure to add an entry with short succinct description of the change as well as link to this pull request to the respective release notes file, if applicable.

    Release notes files:

    • If anything under src/Compiler has been changed, please make sure to make an entry in docs/release-notes/.FSharp.Compiler.Service/<version>.md, where <version> is usually "highest" one, e.g. 42.8.200
    • If language feature was added (i.e. LanguageFeatures.fsi was changed), please add it to docs/releae-notes/.Language/preview.md
    • If a change to FSharp.Core was made, please make sure to edit docs/release-notes/.FSharp.Core/<version>.md where version is "highest" one, e.g. 8.0.200.

    Information about the release notes entries format can be found in the documentation.
    Example:

    If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

@github-actions

github-actionsBot commented Feb 10, 2024

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/8.0.300.md
LanguageFeatures.fsidocs/release-notes/.Language/preview.md

@ijklam

Copy link
Copy Markdown
ContributorAuthor

Where should I add tests to?

Comment threadsrc/Compiler/SyntaxTree/SyntaxTree.fsi Outdated
@vzarytovskii

vzarytovskii commented Feb 10, 2024

Copy link
Copy Markdown
Member

Where should I add tests to?

They should go to ComponentTests probably.

@edgarfgp

Copy link
Copy Markdown
Contributor

@ijklam

Copy link
Copy Markdown
ContributorAuthor

Should this also be allowed for abstract properties? Such as:

typeIA=abstractB:intwith get,internal set

@ijklam

Copy link
Copy Markdown
ContributorAuthor

Should this also be allowed for abstract properties? Such as:

typeIA=abstractB:intwith get,internal set

It seems that abstract members doesn't allow access modifiers

@ijklam
ijklam marked this pull request as ready for review February 11, 2024 15:59
@ijklam
ijklam requested a review from a team as a code ownerFebruary 11, 2024 15:59
@ijklam

Copy link
Copy Markdown
ContributorAuthor

By the way, access modifiers before getter and setter will be ignored and produce a warning in signature files

@ijklamijklam changed the title [WIP]Allow access modifies to auto properties getters and settersAllow access modifiers to auto properties getters and settersFeb 12, 2024
@ijklam

Copy link
Copy Markdown
ContributorAuthor

will anyone make reviews on this pr?

@vzarytovskii

vzarytovskii commented Feb 28, 2024

Copy link
Copy Markdown
Member

will anyone make reviews on this pr?

Yes, we will shortly, we're a bit short-handed now, a bunch of folks are off.

@vzarytovskii
vzarytovskii enabled auto-merge (squash) March 1, 2024 10:29
@edgarfgp

edgarfgp commented Mar 1, 2024

Copy link
Copy Markdown
Contributor

By the way, access modifiers before getter and setter will be ignored and produce a warning in signature files

Would this mean that a private val member with private getter and public setter would be usable from the outside ?

typeA()=member valprivateX=0withpublic get,private set
leta= A()
a.X // ? 

If that is the case we should add a compiler error saying that there are conflicting access modifiers.

auto-merge was automatically disabled March 1, 2024 12:29

Head branch was pushed to by a user without write access

@ijklam

Copy link
Copy Markdown
ContributorAuthor
typeA()=member valprivateX=0withpublic get,private set
typeA()=// Error: When the visibility for a property is specified, setting the visibility of the set or get method is not allowed.member valprivateX=0withpublic get,private set
// Okmember valX=0withpublic get,private set
// Okmember valprivateX=0with get, set

member val X = 0 with public get, private set in signature files should be written as following, and can be usable from outside of A

typeA=new: unit -> A
memberpublicD:int with getmemberprivateD:int with set

@ijklam

Copy link
Copy Markdown
ContributorAuthor

I found that in ILSpy, member val private A = 0 with get, set and member val A = 0 with internal get, private set both produce a internal property. Is it correct behavior?

internalintA{[CompilerGenerated][DebuggerNonUserCode]get{return A@;}[CompilerGenerated][DebuggerNonUserCode]set{
A@ = value;}}

@vzarytovskii

Copy link
Copy Markdown
Member

I found that in ILSpy, member val private A = 0 with get, set and member val A = 0 with internal get, private set both produce a internal property. Is it correct behavior?

internalintA{[CompilerGenerated][DebuggerNonUserCode]get{return A@;}[CompilerGenerated][DebuggerNonUserCode]set{
A@ = value;}}

Yes, current compiler always emits everything (private and internal) as internal.

@ijklam

Copy link
Copy Markdown
ContributorAuthor

@vzarytovskii Still has a test failed.

Failed FSharpChecker.TransparentCompiler.File is not checked twice [291 ms] Error Message: Assert.Equal() Failure Expected: FSharpList<JobEvent> [Weakened, Requested, Started, Finished] Actual: FSharpList<JobEvent> [Weakened, Requested, Started] Stack Trace: at FSharpChecker.TransparentCompiler.File is not checked twice() in /home/vsts/work/1/s/tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs:line 242 at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) 

@psfinaki

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@vzarytovskiivzarytovskii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff as always, thanks!

@vzarytovskii
vzarytovskii enabled auto-merge (squash) March 4, 2024 19:33

@psfinakipsfinaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, great testing. Sorry for nitpicking

Comment threadsrc/Compiler/FSComp.txt Outdated
auto-merge was automatically disabled March 5, 2024 14:10

Head branch was pushed to by a user without write access

@psfinaki

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@psfinaki

Copy link
Copy Markdown
Contributor

/azp run

@psfinaki
psfinaki enabled auto-merge (squash) March 5, 2024 16:11
@github-actions

Copy link
Copy Markdown
Contributor

Caution

Repository is on lockdown for maintenance, all merges are on hold.

@psfinaki
psfinaki merged commit c4f7bed into dotnet:mainMar 7, 2024
@auduchinokauduchinok mentioned this pull request Mar 7, 2024
@auduchinok

Copy link
Copy Markdown
Member

By the way, access modifiers before getter and setter will be ignored and produce a warning in signature files

Why? Would it be possible to support signatures too?

member val X = 0 with public get, private set in signature files should be written as following, and can be usable from outside of A

Can we fix this and allow the same syntax, please?

@vzarytovskii I think we should not release the feature without a proper signature support.

@ijklam

Copy link
Copy Markdown
ContributorAuthor

By the way, access modifiers before getter and setter will be ignored and produce a warning in signature files

Why? Would it be possible to support signatures too?

That might so much thing to change... It also relates to the generation of signature files.

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

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants

@ijklam@vzarytovskii@edgarfgp@psfinaki@auduchinok@nojaf