Skip to content
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

Allow access modifiers to auto properties getters and setters #16687

Merged
merged 22 commits into from
Mar 7, 2024

Conversation

ijklam
Copy link
Contributor

@ijklam ijklam commented Feb 10, 2024

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.

Copy link
Contributor

github-actions bot commented Feb 10, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
LanguageFeatures.fsi docs/release-notes/.Language/preview.md

@ijklam
Copy link
Contributor Author

ijklam commented Feb 10, 2024

Where should I add tests to?

@vzarytovskii
Copy link
Member

vzarytovskii commented Feb 10, 2024

Where should I add tests to?

They should go to ComponentTests probably.

@edgarfgp
Copy link
Contributor

@ijklam
Copy link
Contributor Author

ijklam commented Feb 11, 2024

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

type IA =
  abstract B: int with get, internal set

@ijklam
Copy link
Contributor Author

ijklam commented Feb 11, 2024

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

type IA =
  abstract B: int with 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 owner February 11, 2024 15:59
@ijklam
Copy link
Contributor Author

ijklam commented Feb 11, 2024

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

@ijklam ijklam changed the title [WIP]Allow access modifies to auto properties getters and setters Allow access modifiers to auto properties getters and setters Feb 12, 2024
@ijklam
Copy link
Contributor Author

ijklam commented Feb 28, 2024

will anyone make reviews on this pr?

@vzarytovskii
Copy link
Member

vzarytovskii commented Feb 28, 2024

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
Copy link
Contributor

edgarfgp commented Mar 1, 2024

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 ?

type A() =
    member val private X = 0 with public get, private set

let a = 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
Contributor Author

ijklam commented Mar 1, 2024

type A() =
    member val private X = 0 with public get, private set
type A() =
    // Error: When the visibility for a property is specified, setting the visibility of the set or get method is not allowed.
    member val private X = 0 with public get, private set
    // Ok
    member val X = 0 with public get, private set
    // Ok
    member val private X = 0 with 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

type A =
    new: unit -> A
    member public D: int with get
    member private D: int with set

@ijklam
Copy link
Contributor Author

ijklam commented Mar 1, 2024

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?

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

@vzarytovskii
Copy link
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?

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

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

@ijklam
Copy link
Contributor Author

ijklam commented Mar 2, 2024

@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
Member

psfinaki commented Mar 4, 2024

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Member

@vzarytovskii vzarytovskii left a comment

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
Copy link
Member

@psfinaki psfinaki left a comment

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

auto-merge was automatically disabled March 5, 2024 14:10

Head branch was pushed to by a user without write access

@psfinaki
Copy link
Member

psfinaki commented Mar 5, 2024

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@psfinaki
Copy link
Member

psfinaki commented Mar 5, 2024

/azp run

@psfinaki psfinaki enabled auto-merge (squash) March 5, 2024 16:11
Copy link
Contributor

github-actions bot commented Mar 7, 2024

Caution

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

@psfinaki psfinaki merged commit c4f7bed into dotnet:main Mar 7, 2024
31 of 32 checks passed
@auduchinok
Copy link
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
Contributor Author

ijklam commented Mar 7, 2024

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.

KevinRansom added a commit that referenced this pull request Mar 7, 2024
Revert "Allow access modifiers to auto properties getters and setters (#16687)"
Sign up for free to 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