Skip to content

Commit 6fac9b9

Browse files
ijklamvzarytovskiipsfinaki
authored
Allow access modifiers to auto properties getters and setters (#16861)
* Allow access modifies to auto properties * move types * update release note * Put it under preview flag * add and update baseline * move checks leave parser * update ServiceNavigation; fantomas * add tests * fix tests * fix tests * fix tests * fix tests * fix * fix * fix * fix * add spaces * fix grammar * support in signature file * update test * Update preview.md * fix support for tooling * fix * format fix sig file generate * put tooling new feature under langFeature flag * format * fix typo * fix test; format * fix test * fix test * add test * typo * update baseline * add error tcAccessModifiersNotAllowedInSRTPConstraint update release note * fix build; check new feature and error under preview * format * fix xlf * update test * update xlf * Fix tests * Updated release notes * Update bsl * Fix baseline --------- Co-authored-by: Vlad Zarytovskii <[email protected]> Co-authored-by: Petr <[email protected]>
1 parent ed4263f commit 6fac9b9

File tree

133 files changed

+1164
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+1164
-311
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Parser: recover on missing union case fields (PR [#17452](https://github.com/dotnet/fsharp/pull/17452))
1616
* Parser: recover on missing union case field types (PR [#17455](https://github.com/dotnet/fsharp/pull/17455))
1717
* Sink: report function domain type ([PR #17470](https://github.com/dotnet/fsharp/pull/17470))
18+
* 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))
1819
* Render C# nullable-analysis attributes in tooltips ([PR #17485](https://github.com/dotnet/fsharp/pull/17485))
1920

2021
### Changed

docs/release-notes/.Language/preview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Bidirectional F#/C# interop for 'unmanaged' constraint. ([PR #12154](https://github.com/dotnet/fsharp/pull/12154))
88
* 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))
99
* 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))
10+
* 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))
1011
* Allow #nowarn to support the FS prefix on error codes to disable warnings ([Issue #17206](https://github.com/dotnet/fsharp/issues/16447), [PR #17209](https://github.com/dotnet/fsharp/pull/17209))
1112
* Allow ParsedHashDirectives to have argument types other than strings ([Issue #17240](https://github.com/dotnet/fsharp/issues/16447), [PR #17209](https://github.com/dotnet/fsharp/pull/17209))
1213
* Support empty-bodied computation expressions. ([Language suggestion #1232](https://github.com/fsharp/fslang-suggestions/issues/1232), [PR #17352](https://github.com/dotnet/fsharp/pull/17352))

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,7 +4325,7 @@ module TcDeclarations =
43254325
| _ -> ()
43264326

43274327
/// Split auto-properties into 'let' and 'member' bindings
4328-
let private SplitAutoProps members =
4328+
let private SplitAutoProps (g: TcGlobals) members =
43294329
let membersIncludingAutoProps, vals_Inherits_Abstractslots =
43304330
members |> List.partition (fun memb ->
43314331
match memb with
@@ -4375,7 +4375,7 @@ module TcDeclarations =
43754375
let rec postAutoProps memb =
43764376
match memb with
43774377
| SynMemberDefn.AutoProperty(ident = id) when String.IsNullOrEmpty(id.idText) -> []
4378-
| SynMemberDefn.AutoProperty(attributes=Attributes attribs; isStatic=isStatic; ident=id; typeOpt=tyOpt; propKind=propKind; memberFlags=memberFlags; memberFlagsForSet=memberFlagsForSet; xmlDoc=xmlDoc; accessibility=access; trivia = { GetSetKeywords = mGetSetOpt }) ->
4378+
| SynMemberDefn.AutoProperty(attributes=Attributes attribs; isStatic=isStatic; ident=id; typeOpt=tyOpt; propKind=propKind; memberFlags=memberFlags; memberFlagsForSet=memberFlagsForSet; xmlDoc=xmlDoc; trivia = { GetSetKeywords = mGetSetOpt }; accessibility = access) ->
43794379
let mMemberPortion = id.idRange
43804380
// Only the keep the non-field-targeted attributes
43814381
let attribs = attribs |> List.filter (fun a -> match a.Target with Some t when t.idText = "field" -> false | _ -> true)
@@ -4388,7 +4388,8 @@ module TcDeclarations =
43884388
match propKind, mGetSetOpt with
43894389
| SynMemberKind.PropertySet, Some getSetKeywords -> errorR(Error(FSComp.SR.parsMutableOnAutoPropertyShouldBeGetSetNotJustSet(), getSetKeywords.Range))
43904390
| _ -> ()
4391-
4391+
4392+
let getterAccess, setterAccess = getGetterSetterAccess access propKind g.langVersion
43924393
[
43934394
match propKind with
43944395
| SynMemberKind.Member
@@ -4398,7 +4399,7 @@ module TcDeclarations =
43984399
let rhsExpr = SynExpr.Ident fldId
43994400
let retInfo = match tyOpt with None -> None | Some ty -> Some (None, SynReturnInfo((ty, SynInfo.unnamedRetVal), ty.Range))
44004401
let attribs = mkAttributeList attribs mMemberPortion
4401-
let binding = mkSynBinding (xmlDoc, headPat) (access, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, retInfo, rhsExpr, rhsExpr.Range, [], attribs, Some memberFlags, SynBindingTrivia.Zero)
4402+
let binding = mkSynBinding (xmlDoc, headPat) (getterAccess, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, retInfo, rhsExpr, rhsExpr.Range, [], attribs, Some memberFlags, SynBindingTrivia.Zero)
44024403
SynMemberDefn.Member (binding, mMemberPortion)
44034404
yield getter
44044405
| _ -> ()
@@ -4410,7 +4411,7 @@ module TcDeclarations =
44104411
let vId = ident("v", mMemberPortion)
44114412
let headPat = SynPat.LongIdent (SynLongIdent(headPatIds, [], List.replicate headPatIds.Length None), None, Some noInferredTypars, SynArgPats.Pats [mkSynPatVar None vId], None, mMemberPortion)
44124413
let rhsExpr = mkSynAssign (SynExpr.Ident fldId) (SynExpr.Ident vId)
4413-
let binding = mkSynBinding (xmlDoc, headPat) (access, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, None, rhsExpr, rhsExpr.Range, [], [], Some memberFlagsForSet, SynBindingTrivia.Zero)
4414+
let binding = mkSynBinding (xmlDoc, headPat) (setterAccess, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, None, rhsExpr, rhsExpr.Range, [], [], Some memberFlagsForSet, SynBindingTrivia.Zero)
44144415
SynMemberDefn.Member (binding, mMemberPortion)
44154416
yield setter
44164417
| _ -> ()]
@@ -4434,9 +4435,9 @@ module TcDeclarations =
44344435
/// where simpleRepr can contain inherit type, declared fields and virtual slots.
44354436
/// body = members
44364437
/// where members contain methods/overrides, also implicit ctor, inheritCall and local definitions.
4437-
let rec private SplitTyconDefn (SynTypeDefn(typeInfo=synTyconInfo;typeRepr=trepr; members=extraMembers)) =
4438+
let rec private SplitTyconDefn g (SynTypeDefn(typeInfo=synTyconInfo;typeRepr=trepr; members=extraMembers)) =
44384439
let extraMembers = desugarGetSetMembers extraMembers
4439-
let extraMembers, extra_vals_Inherits_Abstractslots = SplitAutoProps extraMembers
4440+
let extraMembers, extra_vals_Inherits_Abstractslots = SplitAutoProps g extraMembers
44404441
let implements1 = extraMembers |> List.choose (function SynMemberDefn.Interface (interfaceType=ty) -> Some(ty, ty.Range) | _ -> None)
44414442

44424443
match trepr with
@@ -4457,7 +4458,7 @@ module TcDeclarations =
44574458

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

4460-
let members, _vals_Inherits_Abstractslots = SplitAutoProps members
4461+
let members, _vals_Inherits_Abstractslots = SplitAutoProps g members
44614462

44624463
let isConcrete =
44634464
members |> List.exists (function
@@ -4519,7 +4520,7 @@ module TcDeclarations =
45194520

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

45244525
// Create the entities for each module and type definition, and process the core representation of each type definition.
45254526
let tycons, envMutRecPrelim, mutRecDefnsAfterCore =

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4132,6 +4132,20 @@ and TcPseudoMemberSpec cenv newOk env synTypes tpenv synMemberSig m =
41324132
let members, tpenv = TcValSpec cenv env ModuleOrMemberBinding newOk ExprContainerInfo (Some memberFlags) (Some (List.head tys)) tpenv synValSig []
41334133
match members with
41344134
| [ValSpecResult(_, _, id, _, _, memberConstraintTy, prelimValReprInfo, _)] ->
4135+
4136+
match synValSig with
4137+
| SynValSig(accessibility = access) ->
4138+
match access with
4139+
| SynValSigAccess.Single(Some access)
4140+
| SynValSigAccess.GetSet(Some access, _, _)
4141+
| SynValSigAccess.GetSet(_, Some access, _)
4142+
| SynValSigAccess.GetSet(_, _, Some access) ->
4143+
if g.langVersion.SupportsFeature(LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters) then
4144+
errorR(Error(FSComp.SR.tcAccessModifiersNotAllowedInSRTPConstraint(), access.Range))
4145+
else
4146+
warning(Error(FSComp.SR.tcAccessModifiersNotAllowedInSRTPConstraint(), access.Range))
4147+
| _ -> ()
4148+
41354149
let memberConstraintTypars, _ = tryDestForallTy g memberConstraintTy
41364150
let valReprInfo = TranslatePartialValReprInfo memberConstraintTypars prelimValReprInfo
41374151
let _, _, curriedArgInfos, returnTy, _ = GetValReprTypeInCompiledForm g valReprInfo 0 memberConstraintTy m
@@ -12702,8 +12716,22 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
1270212716

1270312717
let valinfos, tpenv = TcValSpec cenv env declKind newOk containerInfo memFlagsOpt None tpenv synValSig attrs
1270412718
let denv = env.DisplayEnv
12719+
let viss =
12720+
match memFlagsOpt with
12721+
| Some ({MemberKind = SynMemberKind.PropertyGetSet as propKind}) ->
12722+
let getterAccess, setterAccess = getGetterSetterAccess vis propKind g.langVersion
12723+
List.init valinfos.Length (fun i -> if i = 0 then getterAccess else setterAccess)
12724+
| Some ({MemberKind = SynMemberKind.PropertyGet as propKind}) ->
12725+
let getterAccess, _ = getGetterSetterAccess vis propKind g.langVersion
12726+
List.init valinfos.Length (fun _ -> getterAccess)
12727+
| Some ({MemberKind = SynMemberKind.PropertySet as propKind}) ->
12728+
let _, setterAccess = getGetterSetterAccess vis propKind g.langVersion
12729+
List.init valinfos.Length (fun _ -> setterAccess)
12730+
| _ ->
12731+
List.init valinfos.Length (fun _ -> vis.SingleAccess())
12732+
let valinfos = List.zip valinfos viss
1270512733

12706-
(tpenv, valinfos) ||> List.mapFold (fun tpenv valSpecResult ->
12734+
(tpenv, valinfos) ||> List.mapFold (fun tpenv (valSpecResult, vis) ->
1270712735

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

0 commit comments

Comments
 (0)