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 #16861

Merged
merged 65 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
ec79e85
Allow access modifies to auto properties
ijklam Feb 10, 2024
47f34ab
move types
ijklam Feb 10, 2024
76e615b
update release note
ijklam Feb 10, 2024
5c3b230
Put it under preview flag
ijklam Feb 10, 2024
f974953
add and update baseline
ijklam Feb 10, 2024
3588ada
move checks leave parser
ijklam Feb 11, 2024
09311ef
update ServiceNavigation; fantomas
ijklam Feb 11, 2024
dc04a91
add tests
ijklam Feb 11, 2024
be9cec3
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Mar 1, 2024
6cf5d1c
fix tests
ijklam Mar 1, 2024
d7ae5fb
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Mar 1, 2024
dbc52d4
fix tests
ijklam Mar 1, 2024
f8c2f5b
Merge branch 'access-modifies-to-auto-properties' of https://github.c…
ijklam Mar 1, 2024
fbe1736
fix tests
ijklam Mar 1, 2024
8e3a529
fix tests
ijklam Mar 1, 2024
88e1678
fix
ijklam Mar 1, 2024
304348f
fix
ijklam Mar 1, 2024
f82df9e
fix
ijklam Mar 1, 2024
97933a5
fix
ijklam Mar 1, 2024
5a2d1fe
add spaces
ijklam Mar 1, 2024
55e9081
fix grammar
ijklam Mar 5, 2024
01d093e
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Mar 7, 2024
34a0010
support in signature file
ijklam Mar 12, 2024
25b75f6
update test
ijklam Mar 12, 2024
6c4ea36
Merge branch 'main' into access-modifies-to-auto-properties
ijklam Mar 12, 2024
eba76af
Update preview.md
ijklam Mar 12, 2024
a6d5a6d
fix
ijklam Mar 12, 2024
6d27474
fix
ijklam Mar 12, 2024
85f83c0
format
ijklam Mar 12, 2024
5d2ae12
put tooling new feature under langFeature flag
ijklam Mar 14, 2024
39d045b
format
ijklam Mar 14, 2024
bfde90f
fix typo
ijklam Mar 14, 2024
46fe0cc
Merge branch 'main' into access-modifies-to-auto-properties
ijklam Apr 7, 2024
4a2a754
fix test; format
ijklam Apr 7, 2024
14bfbad
fix test
ijklam Apr 7, 2024
dd957ee
fix test
ijklam Apr 7, 2024
fd2caaa
add test
ijklam Apr 7, 2024
316a9ea
typo
ijklam Apr 7, 2024
f027ffe
update baseline
ijklam Apr 8, 2024
fcc6d97
Merge branch 'dotnet:main' into access-modifies-to-auto-properties
ijklam Apr 8, 2024
9fcf95f
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Apr 25, 2024
49cbdad
Merge branch 'main' into access-modifies-to-auto-properties
ijklam Apr 29, 2024
9102fee
add error tcAccessModifiersNotAllowedInSRTPConstraint
ijklam Apr 29, 2024
97a6c59
fix build; check new feature and error under preview
ijklam Apr 29, 2024
d064e3c
format
ijklam Apr 29, 2024
5023f21
Merge branch 'main' into access-modifies-to-auto-properties
ijklam May 9, 2024
a0e2b55
fix xlf
ijklam May 9, 2024
86728d1
update test
ijklam May 9, 2024
79655c8
Merge branch 'main' into access-modifies-to-auto-properties
ijklam May 9, 2024
f6d775c
update xlf
ijklam May 9, 2024
8305a85
Merge branch 'main' into access-modifies-to-auto-properties
ijklam May 20, 2024
aa7790f
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii May 22, 2024
ede6c14
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Jun 26, 2024
0249ab4
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Jul 16, 2024
ecc647c
Fix tests
vzarytovskii Jul 16, 2024
70ba918
Updated release notes
vzarytovskii Jul 16, 2024
4438cd6
Merge branch 'main' into access-modifies-to-auto-properties
psfinaki Jul 22, 2024
b501108
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Jul 24, 2024
6838437
Update bsl
vzarytovskii Jul 24, 2024
c037354
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Jul 29, 2024
b344aea
Fix baseline
vzarytovskii Jul 29, 2024
d5a3509
Merge remote-tracking branch 'upstream/main' into access-modifies-to-…
ijklam Aug 10, 2024
dc427d8
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Aug 10, 2024
ba25173
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Aug 10, 2024
3adaf31
Merge branch 'main' into access-modifies-to-auto-properties
vzarytovskii Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.400.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
### Added

* Generate new `Equals` overload to avoid boxing for structural comparison ([PR #16857](https://github.com/dotnet/fsharp/pull/16857))
* Allow access modifies to auto properties getters and setters ([PR 16687](https://github.com/dotnet/fsharp/pull/16687), [PR 16861](https://github.com/dotnet/fsharp/pull/16861), [Language suggestion #430](https://github.com/fsharp/fslang-suggestions/issues/430))

### Changed
* Enforce `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Bidirectional F#/C# interop for 'unmanaged' constraint. ([PR #12154](https://github.com/dotnet/fsharp/pull/12154))
* Make `.Is*` discriminated union properties visible. ([Language suggestion #222](https://github.com/fsharp/fslang-suggestions/issues/222), [PR #16341](https://github.com/dotnet/fsharp/pull/16341))
* Allow returning bool instead of unit option for partial active patterns. ([Language suggestion #1041](https://github.com/fsharp/fslang-suggestions/issues/1041), [PR #16473](https://github.com/dotnet/fsharp/pull/16473))
* Allow access modifies to auto properties getters and setters ([PR 16687](https://github.com/dotnet/fsharp/pull/16687), [PR 16861](https://github.com/dotnet/fsharp/pull/16861), [Language suggestion #430](https://github.com/fsharp/fslang-suggestions/issues/430))

### Fixed

Expand Down
19 changes: 10 additions & 9 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4308,7 +4308,7 @@ module TcDeclarations =
| _ -> ()

/// Split auto-properties into 'let' and 'member' bindings
let private SplitAutoProps members =
let private SplitAutoProps (g: TcGlobals) members =
let membersIncludingAutoProps, vals_Inherits_Abstractslots =
members |> List.partition (fun memb ->
match memb with
Expand Down Expand Up @@ -4358,7 +4358,7 @@ module TcDeclarations =
let rec postAutoProps memb =
match memb with
| SynMemberDefn.AutoProperty(ident = id) when String.IsNullOrEmpty(id.idText) -> []
| SynMemberDefn.AutoProperty(attributes=Attributes attribs; isStatic=isStatic; ident=id; typeOpt=tyOpt; propKind=propKind; memberFlags=memberFlags; memberFlagsForSet=memberFlagsForSet; xmlDoc=xmlDoc; accessibility=access; trivia = { GetSetKeywords = mGetSetOpt }) ->
| SynMemberDefn.AutoProperty(attributes=Attributes attribs; isStatic=isStatic; ident=id; typeOpt=tyOpt; propKind=propKind; memberFlags=memberFlags; memberFlagsForSet=memberFlagsForSet; xmlDoc=xmlDoc; trivia = { GetSetKeywords = mGetSetOpt }; accessibility = access) ->
let mMemberPortion = id.idRange
// Only the keep the non-field-targeted attributes
let attribs = attribs |> List.filter (fun a -> match a.Target with Some t when t.idText = "field" -> false | _ -> true)
Expand All @@ -4371,7 +4371,8 @@ module TcDeclarations =
match propKind, mGetSetOpt with
| SynMemberKind.PropertySet, Some getSetKeywords -> errorR(Error(FSComp.SR.parsMutableOnAutoPropertyShouldBeGetSetNotJustSet(), getSetKeywords.Range))
| _ -> ()


let getterAccess, setterAccess = getGetterSetterAccess access propKind g.langVersion
[
match propKind with
| SynMemberKind.Member
Expand All @@ -4381,7 +4382,7 @@ module TcDeclarations =
let rhsExpr = SynExpr.Ident fldId
let retInfo = match tyOpt with None -> None | Some ty -> Some (None, SynReturnInfo((ty, SynInfo.unnamedRetVal), ty.Range))
let attribs = mkAttributeList attribs mMemberPortion
let binding = mkSynBinding (xmlDoc, headPat) (access, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, retInfo, rhsExpr, rhsExpr.Range, [], attribs, Some memberFlags, SynBindingTrivia.Zero)
let binding = mkSynBinding (xmlDoc, headPat) (getterAccess, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, retInfo, rhsExpr, rhsExpr.Range, [], attribs, Some memberFlags, SynBindingTrivia.Zero)
SynMemberDefn.Member (binding, mMemberPortion)
yield getter
| _ -> ()
Expand All @@ -4393,7 +4394,7 @@ module TcDeclarations =
let vId = ident("v", mMemberPortion)
let headPat = SynPat.LongIdent (SynLongIdent(headPatIds, [], List.replicate headPatIds.Length None), None, Some noInferredTypars, SynArgPats.Pats [mkSynPatVar None vId], None, mMemberPortion)
let rhsExpr = mkSynAssign (SynExpr.Ident fldId) (SynExpr.Ident vId)
let binding = mkSynBinding (xmlDoc, headPat) (access, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, None, rhsExpr, rhsExpr.Range, [], [], Some memberFlagsForSet, SynBindingTrivia.Zero)
let binding = mkSynBinding (xmlDoc, headPat) (setterAccess, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, None, rhsExpr, rhsExpr.Range, [], [], Some memberFlagsForSet, SynBindingTrivia.Zero)
SynMemberDefn.Member (binding, mMemberPortion)
yield setter
| _ -> ()]
Expand All @@ -4417,9 +4418,9 @@ module TcDeclarations =
/// where simpleRepr can contain inherit type, declared fields and virtual slots.
/// body = members
/// where members contain methods/overrides, also implicit ctor, inheritCall and local definitions.
let rec private SplitTyconDefn (SynTypeDefn(typeInfo=synTyconInfo;typeRepr=trepr; members=extraMembers)) =
let rec private SplitTyconDefn g (SynTypeDefn(typeInfo=synTyconInfo;typeRepr=trepr; members=extraMembers)) =
let extraMembers = desugarGetSetMembers extraMembers
let extraMembers, extra_vals_Inherits_Abstractslots = SplitAutoProps extraMembers
let extraMembers, extra_vals_Inherits_Abstractslots = SplitAutoProps g extraMembers
let implements1 = extraMembers |> List.choose (function SynMemberDefn.Interface (interfaceType=ty) -> Some(ty, ty.Range) | _ -> None)

match trepr with
Expand All @@ -4440,7 +4441,7 @@ module TcDeclarations =

let slotsigs = members |> List.choose (function SynMemberDefn.AbstractSlot (slotSig = x; flags = y) -> Some(x, y) | _ -> None)

let members, _vals_Inherits_Abstractslots = SplitAutoProps members
let members, _vals_Inherits_Abstractslots = SplitAutoProps g members

let isConcrete =
members |> List.exists (function
Expand Down Expand Up @@ -4502,7 +4503,7 @@ module TcDeclarations =

// Split the definitions into "core representations" and "members". The code to process core representations
// is shared between processing of signature files and implementation files.
let mutRecDefnsAfterSplit = mutRecDefns |> MutRecShapes.mapTycons SplitTyconDefn
let mutRecDefnsAfterSplit = mutRecDefns |> MutRecShapes.mapTycons (fun i -> SplitTyconDefn g i)

// Create the entities for each module and type definition, and process the core representation of each type definition.
let tycons, envMutRecPrelim, mutRecDefnsAfterCore =
Expand Down
30 changes: 29 additions & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,20 @@ and TcPseudoMemberSpec cenv newOk env synTypes tpenv synMemberSig m =
let members, tpenv = TcValSpec cenv env ModuleOrMemberBinding newOk ExprContainerInfo (Some memberFlags) (Some (List.head tys)) tpenv synValSig []
match members with
| [ValSpecResult(_, _, id, _, _, memberConstraintTy, prelimValReprInfo, _)] ->

match synValSig with
| SynValSig(accessibility = access) ->
match access with
| SynValSigAccess.Single(Some access)
| SynValSigAccess.GetSet(Some access, _, _)
| SynValSigAccess.GetSet(_, Some access, _)
| SynValSigAccess.GetSet(_, _, Some access) ->
if g.langVersion.SupportsFeature(LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters) then
errorR(Error(FSComp.SR.tcAccessModifiersNotAllowedInSRTPConstraint(), access.Range))
else
warning(Error(FSComp.SR.tcAccessModifiersNotAllowedInSRTPConstraint(), access.Range))
| _ -> ()

let memberConstraintTypars, _ = tryDestForallTy g memberConstraintTy
let valReprInfo = TranslatePartialValReprInfo memberConstraintTypars prelimValReprInfo
let _, _, curriedArgInfos, returnTy, _ = GetValReprTypeInCompiledForm g valReprInfo 0 memberConstraintTy m
Expand Down Expand Up @@ -12601,8 +12615,22 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind

let valinfos, tpenv = TcValSpec cenv env declKind newOk containerInfo memFlagsOpt None tpenv synValSig attrs
let denv = env.DisplayEnv
let viss =
match memFlagsOpt with
| Some ({MemberKind = SynMemberKind.PropertyGetSet as propKind}) ->
let getterAccess, setterAccess = getGetterSetterAccess vis propKind g.langVersion
List.init valinfos.Length (fun i -> if i = 0 then getterAccess else setterAccess)
| Some ({MemberKind = SynMemberKind.PropertyGet as propKind}) ->
let getterAccess, _ = getGetterSetterAccess vis propKind g.langVersion
List.init valinfos.Length (fun _ -> getterAccess)
| Some ({MemberKind = SynMemberKind.PropertySet as propKind}) ->
let _, setterAccess = getGetterSetterAccess vis propKind g.langVersion
List.init valinfos.Length (fun _ -> setterAccess)
| _ ->
List.init valinfos.Length (fun _ -> vis.SingleAccess())
let valinfos = List.zip valinfos viss

(tpenv, valinfos) ||> List.mapFold (fun tpenv valSpecResult ->
(tpenv, valinfos) ||> List.mapFold (fun tpenv (valSpecResult, vis) ->

let (ValSpecResult (altActualParent, memberInfoOpt, id, enclosingDeclaredTypars, declaredTypars, ty, prelimValReprInfo, declKind)) = valSpecResult

Expand Down
Loading
Loading