fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Allow access modifiers to auto properties getters and setters

Open Tangent-90 opened this issue 5 months ago • 7 comments

Description

Implements this suggestion

图片

Checklist

  • [x] RFC added

  • [x] Put it under preview flag

  • [ ] Test cases added

  • [ ] Performance benchmarks added in case of performance changes

  • [x] 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.

Tangent-90 avatar Feb 10 '24 09:02 Tangent-90

:heavy_exclamation_mark: Release notes required


:white_check_mark: 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

github-actions[bot] avatar Feb 10 '24 09:02 github-actions[bot]

Where should I add tests to?

Tangent-90 avatar Feb 10 '24 13:02 Tangent-90

Where should I add tests to?

They should go to ComponentTests probably.

vzarytovskii avatar Feb 10 '24 19:02 vzarytovskii

Where should I add tests to?

I think this would be a good place https://github.com/dotnet/fsharp/tree/main/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/MemberDefinitions

edgarfgp avatar Feb 10 '24 21:02 edgarfgp

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

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

Tangent-90 avatar Feb 11 '24 02:02 Tangent-90

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

Tangent-90 avatar Feb 11 '24 02:02 Tangent-90

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

Tangent-90 avatar Feb 11 '24 16:02 Tangent-90

will anyone make reviews on this pr?

Tangent-90 avatar Feb 28 '24 17:02 Tangent-90

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 avatar Feb 28 '24 17:02 vzarytovskii

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.

edgarfgp avatar Mar 01 '24 12:03 edgarfgp

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

Tangent-90 avatar Mar 01 '24 12:03 Tangent-90

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;
		}
	}

Tangent-90 avatar Mar 01 '24 12:03 Tangent-90

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.

vzarytovskii avatar Mar 01 '24 14:03 vzarytovskii

@Tangent-90 ugh, it seems you're facing some issues with tests post merge, sorry about that. Let me know if I can help resolving those.

vzarytovskii avatar Mar 01 '24 18:03 vzarytovskii

@Tangent-90 ugh, it seems you're facing some issues with tests post merge, sorry about that. Let me know if I can help resolving those.

Just some boring error messages position mismatched in tests...

Tangent-90 avatar Mar 01 '24 18:03 Tangent-90

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

Tangent-90 avatar Mar 02 '24 03:03 Tangent-90

/azp run

psfinaki avatar Mar 04 '24 15:03 psfinaki

Azure Pipelines successfully started running 2 pipeline(s).

azure-pipelines[bot] avatar Mar 04 '24 15:03 azure-pipelines[bot]

/azp run

psfinaki avatar Mar 05 '24 14:03 psfinaki

Azure Pipelines successfully started running 2 pipeline(s).

azure-pipelines[bot] avatar Mar 05 '24 14:03 azure-pipelines[bot]

/azp run

psfinaki avatar Mar 05 '24 16:03 psfinaki

[!CAUTION] Repository is on lockdown for maintenance, all merges are on hold.

github-actions[bot] avatar Mar 07 '24 11:03 github-actions[bot]

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.

auduchinok avatar Mar 07 '24 17:03 auduchinok

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.

Tangent-90 avatar Mar 07 '24 18:03 Tangent-90