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

Report auto property redux #16116

Merged
merged 24 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8ea0e3
Report property in PostInferenceChecks.
nojaf Oct 11, 2023
33d7d93
Move property item creation back to CheckDeclarations.
nojaf Oct 12, 2023
97a34b8
Use StringComparison.Ordinal
nojaf Nov 10, 2023
9e22857
Update unit test according to new world.
nojaf Nov 10, 2023
f9b5ea6
Update tests
nojaf Nov 13, 2023
4c69ba5
Update SyntaxTree tests
nojaf Nov 13, 2023
f1ab837
Update SyntaxTree tests
nojaf Nov 13, 2023
14258ec
Update unit tests
nojaf Nov 14, 2023
995959d
Return single property tooltip.
nojaf Nov 14, 2023
cef7c51
Maybe fix fsharpqa tests
nojaf Nov 14, 2023
d55e99f
Merge branch 'main' into report-auto-property-redux
nojaf Nov 14, 2023
3f0202d
Maybe fix fsharpqa tests
nojaf Nov 14, 2023
e5bdefb
Merge branch 'report-auto-property-redux' of https://github.com/nojaf…
nojaf Nov 14, 2023
c99df5f
Merge branch 'main' into report-auto-property-redux
nojaf Nov 15, 2023
1ddb15a
Update tests
nojaf Nov 15, 2023
b8ff0ef
Merge branch 'main' into report-auto-property-redux
psfinaki Nov 15, 2023
e7261e9
Merge branch 'main' into report-auto-property-redux
nojaf Nov 16, 2023
3706586
Update test
nojaf Nov 16, 2023
9daa478
Add tests for properties during critical errors.
nojaf Nov 16, 2023
b84edcb
Add test for property symbol on interface.
nojaf Nov 16, 2023
100dbc5
Revert PostInferenceChecks.fs
nojaf Nov 16, 2023
159b013
Merge branch 'main' into report-auto-property-redux
nojaf Nov 20, 2023
9187b0b
Clean up
nojaf Nov 21, 2023
5385172
Merge branch 'main' into report-auto-property-redux
nojaf Nov 21, 2023
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
61 changes: 20 additions & 41 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -997,25 +997,30 @@ module MutRecBindingChecking =
for b1, b2 in List.pairwise defnAs do
match b1, b2 with
| TyconBindingPhase2A.Phase2AMember {
SyntacticBinding = NormalizedBinding(valSynData = SynValData(transformedFromProperty = Some getPropertyIdent; memberFlags = Some mf))
SyntacticBinding = NormalizedBinding(pat = SynPat.Named(ident = SynIdent(ident = getIdent)); valSynData = SynValData(memberFlags = Some mf))
nojaf marked this conversation as resolved.
Show resolved Hide resolved
RecBindingInfo = RecursiveBindingInfo(vspec = vGet)
},
TyconBindingPhase2A.Phase2AMember {
SyntacticBinding = NormalizedBinding(valSynData = SynValData(transformedFromProperty = Some setPropertyIdent))
SyntacticBinding = NormalizedBinding(pat = SynPat.Named(ident = SynIdent(ident = setIdent)))
RecBindingInfo = RecursiveBindingInfo(vspec = vSet)
} when Range.equals getPropertyIdent.idRange setPropertyIdent.idRange ->
} when Range.equals getIdent.idRange setIdent.idRange ->
match vGet.ApparentEnclosingEntity with
| ParentNone -> ()
| Parent parentRef ->
let apparentEnclosingType = generalizedTyconRef g parentRef
let vGet, vSet = if mf.MemberKind = SynMemberKind.PropertyGet then vGet, vSet else vSet, vGet
let item =
Item.Property(
getPropertyIdent.idText,
[ PropInfo.FSProp(g, apparentEnclosingType, Some (mkLocalValRef vGet), Some (mkLocalValRef vSet)) ],
Some getPropertyIdent.idRange
)
CallNameResolutionSink cenv.tcSink (getPropertyIdent.idRange, envForTycon.NameEnv, item, emptyTyparInst, ItemOccurence.Binding, envForTycon.eAccessRights)
let apparentEnclosingType = generalizedTyconRef g parentRef
let vGet, vSet = if mf.MemberKind = SynMemberKind.PropertyGet then vGet, vSet else vSet, vGet
let propertyName =
if vGet.Id.idText.StartsWith("get_", StringComparison.Ordinal) then
vGet.Id.idText.Replace("get_", "")
else
vGet.Id.idText
let item =
Item.Property(
propertyName,
[ PropInfo.FSProp(g, apparentEnclosingType, Some (mkLocalValRef vGet), Some (mkLocalValRef vSet)) ],
Some getIdent.idRange
)
CallNameResolutionSink cenv.tcSink (getIdent.idRange, envForTycon.NameEnv, item, emptyTyparInst, ItemOccurence.Binding, envForTycon.eAccessRights)
| _ -> ()

// If no constructor call, insert Phase2AIncrClassCtorJustAfterSuperInit at start
Expand Down Expand Up @@ -4263,6 +4268,8 @@ module TcDeclarations =
// 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)
let fldId = ident (CompilerGeneratedName id.idText, mMemberPortion)
let headPatIds = if isStatic then [id] else [ident ("__", mMemberPortion);id]
nojaf marked this conversation as resolved.
Show resolved Hide resolved
let headPat = SynPat.LongIdent (SynLongIdent(headPatIds, [], List.replicate headPatIds.Length None), None, Some noInferredTypars, SynArgPats.Pats [], None, mMemberPortion)
let memberFlags = { memberFlags with GetterOrSetterIsCompilerGenerated = true }
let memberFlagsForSet = { memberFlagsForSet with GetterOrSetterIsCompilerGenerated = true }

Expand All @@ -4279,20 +4286,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 headPatIds =
let id =
match mGetSetOpt with
| Some (GetSetKeywords.GetSet(get = mGet)) -> Ident(id.idText, mGet)
| _ -> id
if isStatic then [id] else [ident ("__", mMemberPortion);id]
let headPat = SynPat.LongIdent (SynLongIdent(headPatIds, [], List.replicate headPatIds.Length None), None, Some noInferredTypars, SynArgPats.Pats [], None, mMemberPortion)
let binding = mkSynBinding (xmlDoc, headPat) (access, false, false, mMemberPortion, DebugPointAtBinding.NoneAtInvisible, retInfo, rhsExpr, rhsExpr.Range, [], attribs, Some memberFlags, SynBindingTrivia.Zero)
let binding =
match mGetSetOpt with
| Some (GetSetKeywords.GetSet _) ->
// Only add the additional meta data to the SynBinding (SynValData) is both get and set are present.
updatePropertyIdentInSynBinding id binding
| _ -> binding
SynMemberDefn.Member (binding, mMemberPortion)
yield getter
| _ -> ()
Expand All @@ -4301,25 +4295,10 @@ module TcDeclarations =
| SynMemberKind.PropertySet
| SynMemberKind.PropertyGetSet ->
let setter =
let vId =
match mGetSetOpt with
| Some (GetSetKeywords.GetSet(set = mSet)) -> ident("v", mSet)
| _ -> ident("v", mMemberPortion)
let headPatIds =
let id =
match mGetSetOpt with
| Some (GetSetKeywords.GetSet(set = mSet)) -> Ident(id.idText, mSet)
| _ -> id
if isStatic then [id] else [ident ("__", mMemberPortion);id]
let vId = ident("v", mMemberPortion)
nojaf marked this conversation as resolved.
Show resolved Hide resolved
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 =
match mGetSetOpt with
| Some (GetSetKeywords.GetSet _) ->
// Only add the additional meta data to the SynBinding (SynValData) is both get and set are present.
updatePropertyIdentInSynBinding id binding
| _ -> binding
SynMemberDefn.Member (binding, mMemberPortion)
yield setter
| _ -> ()]
Expand Down
27 changes: 12 additions & 15 deletions src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,7 @@ module BindingNormalization =
NormalizedBindingPat(SynPat.InstanceMember(thisId, memberId, toolId, vis, m), PushMultiplePatternsToRhs cenv true args rhsExpr, valSynData, typars)

let private NormalizeStaticMemberBinding (cenv: cenv) (memberFlags: SynMemberFlags) valSynData id vis typars args m rhsExpr =
let (SynValData(valInfo = valSynInfo; thisIdOpt = thisIdOpt; transformedFromProperty = tp)) = valSynData
let (SynValData(valInfo = valSynInfo; thisIdOpt = thisIdOpt)) = valSynData
if memberFlags.IsInstance then
// instance method without adhoc "this" argument
error(Error(FSComp.SR.tcInstanceMemberRequiresTarget(), m))
Expand All @@ -2368,15 +2368,15 @@ module BindingNormalization =
// static property: these transformed into methods taking one "unit" argument
| [], SynMemberKind.Member ->
let memberFlags = {memberFlags with MemberKind = SynMemberKind.PropertyGet}
let valSynData = SynValData(Some memberFlags, valSynInfo, thisIdOpt, tp)
let valSynData = SynValData(Some memberFlags, valSynInfo, thisIdOpt)
NormalizedBindingPat(mkSynPatVar vis id,
PushOnePatternToRhs cenv true (SynPat.Const(SynConst.Unit, m)) rhsExpr,
valSynData,
typars)
| _ -> MakeNormalizedStaticOrValBinding cenv ValOrMemberBinding id vis typars args rhsExpr valSynData

let private NormalizeInstanceMemberBinding (cenv: cenv) (memberFlags: SynMemberFlags) valSynData thisId memberId (toolId: Ident option) vis typars args m rhsExpr =
let (SynValData(_, valSynInfo, thisIdOpt, tap)) = valSynData
let (SynValData(_, valSynInfo, thisIdOpt)) = valSynData

if not memberFlags.IsInstance then
// static method with adhoc "this" argument
Expand All @@ -2400,7 +2400,7 @@ module BindingNormalization =
(SynPat.InstanceMember(thisId, memberId, toolId, vis, m),
PushOnePatternToRhs cenv true (SynPat.Const(SynConst.Unit, m)) rhsExpr,
// Update the member info to record that this is a SynMemberKind.PropertyGet
SynValData(Some memberFlags, valSynInfo, thisIdOpt, tap),
SynValData(Some memberFlags, valSynInfo, thisIdOpt),
typars)

| _ ->
Expand Down Expand Up @@ -2511,10 +2511,10 @@ module EventDeclarationNormalization =
| _ -> error(BadEventTransformation m)

let private ConvertSynData m valSynData =
let (SynValData(memberFlagsOpt, valSynInfo, thisIdOpt, tap)) = valSynData
let (SynValData(memberFlagsOpt, valSynInfo, thisIdOpt)) = valSynData
let memberFlagsOpt = ConvertMemberFlagsOpt m memberFlagsOpt
let valSynInfo = ConvertSynInfo m valSynInfo
SynValData(memberFlagsOpt, valSynInfo, thisIdOpt, tap)
SynValData(memberFlagsOpt, valSynInfo, thisIdOpt)

let rec private RenameBindingPattern f declPattern =
match declPattern with
Expand Down Expand Up @@ -10553,8 +10553,8 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
match rotRetSynAttrs with
| [] -> valSynData
| {Range=mHead} :: _ ->
let (SynValData(valMf, SynValInfo(args, SynArgInfo(attrs, opt, retId)), valId, tap)) = valSynData
SynValData(valMf, SynValInfo(args, SynArgInfo({Attributes=rotRetSynAttrs; Range=mHead} :: attrs, opt, retId)), valId, tap)
let (SynValData(valMf, SynValInfo(args, SynArgInfo(attrs, opt, retId)), valId)) = valSynData
SynValData(valMf, SynValInfo(args, SynArgInfo({Attributes=rotRetSynAttrs; Range=mHead} :: attrs, opt, retId)), valId)
retAttribs, valAttribs, valSynData

let isVolatile = HasFSharpAttribute g g.attrib_VolatileFieldAttribute valAttribs
Expand Down Expand Up @@ -11547,7 +11547,6 @@ and AnalyzeRecursiveInstanceMemberDecl
thisId,
memberId: Ident,
toolId: Ident option,
isTransformedProperty: bool,
bindingAttribs,
vis2,
tcrefContainerInfo,
Expand Down Expand Up @@ -11606,12 +11605,11 @@ and AnalyzeRecursiveInstanceMemberDecl
| None -> None

let memberInfo = MakeMemberDataAndMangledNameForMemberVal(g, tcref, isExtrinsic, bindingAttribs, optInferredImplSlotTys, memberFlags, valSynInfo, memberId, false)
// This line factored in the 'get' or 'set' as the identifier for a property declaration using "with get () = ... and set v = ..."
// We used to factored in the 'get' or 'set' as the identifier for a property declaration using "with get () = ... and set v = ..."
// It has been removed from FSharp.Compiler.Service because we want the property name to be the location of
// the definition of these symbols.
//
// See https://github.com/fsharp/FSharp.Compiler.Service/issues/79.
let memberId = match toolId with Some tid when isTransformedProperty -> ident(memberId.idText, tid.idRange) | _ -> memberId
nojaf marked this conversation as resolved.
Show resolved Hide resolved

envinner, tpenv, memberId, toolId, Some memberInfo, vis, vis2, None, enclosingDeclaredTypars, baseValOpt, explicitTyparInfo, bindingRhs, declaredTypars
| _ ->
Expand All @@ -11626,7 +11624,6 @@ and AnalyzeRecursiveDecl
declaredTypars,
thisIdOpt,
valSynInfo,
isTransformedProperty,
explicitTyparInfo,
newslotsOK,
overridesOK,
Expand Down Expand Up @@ -11671,7 +11668,7 @@ and AnalyzeRecursiveDecl
AnalyzeRecursiveInstanceMemberDecl
(cenv, envinner, tpenv, declKind,
synTyparDecls, valSynInfo, explicitTyparInfo, newslotsOK,
overridesOK, vis1, thisId, memberId, toolId, isTransformedProperty,
overridesOK, vis1, thisId, memberId, toolId,
bindingAttribs, vis2, tcrefContainerInfo,
memberFlagsOpt, ty, bindingRhs, mBinding)

Expand Down Expand Up @@ -11701,7 +11698,7 @@ and AnalyzeAndMakeAndPublishRecursiveValue
// Pull apart the inputs
let (NormalizedBinding(vis1, bindingKind, isInline, isMutable, bindingSynAttribs, bindingXmlDoc, synTyparDecls, valSynData, declPattern, bindingRhs, mBinding, debugPoint)) = binding
let (NormalizedBindingRhs(_, _, bindingExpr)) = bindingRhs
let (SynValData(memberFlagsOpt, valSynInfo, thisIdOpt, transformedFromProperty)) = valSynData
let (SynValData(memberFlagsOpt, valSynInfo, thisIdOpt)) = valSynData
let (ContainerInfo(altActualParent, tcrefContainerInfo)) = containerInfo

let attrTgt = declKind.AllowedAttribTargets memberFlagsOpt
Expand All @@ -11725,7 +11722,7 @@ and AnalyzeAndMakeAndPublishRecursiveValue
let envinner, tpenv, bindingId, toolIdOpt, memberInfoOpt, vis, vis2, safeThisValOpt, enclosingDeclaredTypars, baseValOpt, explicitTyparInfo, bindingRhs, declaredTypars =

AnalyzeRecursiveDecl (cenv, envinner, tpenv, declKind, synTyparDecls, declaredTypars, thisIdOpt, valSynInfo,
transformedFromProperty.IsSome, explicitTyparInfo,
explicitTyparInfo,
newslotsOK, overridesOK, vis1, declPattern, bindingAttribs, tcrefContainerInfo,
memberFlagsOpt, ty, bindingRhs, mBinding)

Expand Down
31 changes: 25 additions & 6 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1968,12 +1968,31 @@ type internal TypeCheckInfo
match declItemsOpt with
| None -> emptyToolTip
| Some (items, denv, _, m) ->
ToolTipText(
items
|> List.map (fun x ->
let symbol = Some(FSharpSymbol.Create(cenv, x.Item))
FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst symbol width)
))
match items with
nojaf marked this conversation as resolved.
Show resolved Hide resolved
| [ { Kind = CompletionItemKind.Property } as prop
{ Kind = CompletionItemKind.Field }
{ Kind = CompletionItemKind.Field } ] ->
let symbol = FSharpSymbol.Create(cenv, prop.Item)

let tt =
FormatStructuredDescriptionOfItem
false
infoReader
tcAccessRights
m
denv
prop.ItemWithInst
(Some symbol)
width

ToolTipText([ tt ])
| _ ->
ToolTipText(
items
|> List.map (fun x ->
let symbol = Some(FSharpSymbol.Create(cenv, x.Item))
FormatStructuredDescriptionOfItem false infoReader tcAccessRights m denv x.ItemWithInst symbol width)
))
(fun err ->
Trace.TraceInformation(sprintf "FCS: recovering from error in GetStructuredToolTipText: '%s'" err)
ToolTipText [ ToolTipElement.CompositionError err ])
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/SyntaxTree/ParseHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ let mkSynMemberDefnGetSet
// should be unreachable, cover just in case
raiseParseErrorAt mWholeBindLhs (FSComp.SR.parsInvalidProperty ())

let valSynData = SynValData(Some(memFlags), valSynInfo, None, None)
let valSynData = SynValData(Some(memFlags), valSynInfo, None)

// Fold together the information from the first lambda pattern and the get/set binding
// This uses the 'this' variable from the first and the patterns for the get/set binding,
Expand Down
6 changes: 1 addition & 5 deletions src/Compiler/SyntaxTree/SyntaxTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,11 +1046,7 @@ type SynAttributes = SynAttributeList list

[<NoEquality; NoComparison>]
type SynValData =
| SynValData of
memberFlags: SynMemberFlags option *
valInfo: SynValInfo *
thisIdOpt: Ident option *
transformedFromProperty: Ident option
| SynValData of memberFlags: SynMemberFlags option * valInfo: SynValInfo * thisIdOpt: Ident option

member x.SynValInfo = (let (SynValData (valInfo = synValInfo)) = x in synValInfo)

Expand Down
8 changes: 1 addition & 7 deletions src/Compiler/SyntaxTree/SyntaxTree.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1195,13 +1195,7 @@ type SynAttributes = SynAttributeList list
/// Represents extra information about the declaration of a value
[<NoEquality; NoComparison>]
type SynValData =
| SynValData of
memberFlags: SynMemberFlags option *
valInfo: SynValInfo *
thisIdOpt: Ident option *
/// Is only populated during type-checking when an property has both a getter and setter.
/// It is used to track the fact that the getter and setter are part of the same property when they are desugared.
transformedFromProperty: Ident option
| SynValData of memberFlags: SynMemberFlags option * valInfo: SynValInfo * thisIdOpt: Ident option

member SynValInfo: SynValInfo

Expand Down
Loading
Loading