Uh oh!
There was an error while loading. Please reload this page.
Report auto property - #15589
Conversation
@nojaf Is there a chance that this change could also help to improve things for non-auto properties too? 😇 typeT1()=memberx.P=0memberx.Pwith set (i:int)=()typeT2()=memberthis.Pwith get _=1andset _ _ =() |
There's also seems to be a crazy way to mix auto properties with normal ones: typeT3()=member valP=1memberthis.Pwith set (i:int)=() |
nojaf
commented
Jul 13, 2023
Not with the current changes but I hope to use the same mechanism for
Because of course, why not 🥳🙈. I don't think my current change would impact that. |
Apparently, it's considered to be a single property in the signature and compiled code. 😞 It looks like the setter from the second declaration is added to the auto property. Ideally, the same property should be reported at both |
nojaf
commented
Jul 17, 2023
Ready for review. |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: dawe <dawedawe@posteo.de>
| FSharp.Compiler.Syntax.SynUnionCaseKind: Int32 get_Tag() | ||
| FSharp.Compiler.Syntax.SynUnionCaseKind: System.String ToString() | ||
| FSharp.Compiler.Syntax.SynValData: FSharp.Compiler.Syntax.SynValData NewSynValData(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynMemberFlags], FSharp.Compiler.Syntax.SynValInfo, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident]) | ||
| FSharp.Compiler.Syntax.SynValData: FSharp.Compiler.Syntax.SynValData NewSynValData(Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.SynMemberFlags], FSharp.Compiler.Syntax.SynValInfo, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.Syntax.Ident]) |
There was a problem hiding this comment.
This is a breaking change, right?
There was a problem hiding this comment.
Strictly speaking yes, but every FCS release has these.
You could say the same thing about the recent changes in https://github.com/dotnet/fsharp/commits/main/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl
vzarytovskii
left a comment
There was a problem hiding this comment.
This one in particular is a bit more scary to me.
@0101@auduchinok@T-Gro please take a look
vzarytovskii
left a comment
There was a problem hiding this comment.
This one in particular is a bit more scary to me.
@0101@auduchinok@T-Gro please take a look
psfinaki
left a comment
There was a problem hiding this comment.
Left a few remarks, mostly minor things and some learning opportunities for me.
Thanks a lot!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| match mGetSetOpt with | ||
| | Some (GetSetKeywords.GetSet(set = mSet)) -> Ident(id.idText, mSet) | ||
| | _ -> id | ||
| if isStatic then [id] else [ident ("__", mMemberPortion);id] |
There was a problem hiding this comment.
On a high level, how do things bubble up if it's static actually?
| @@ -11418,8 +11419,7 @@ and AnalyzeRecursiveInstanceMemberDecl | |||
| // the definition of these symbols. | |||
| // | |||
| // See https://github.com/fsharp/FSharp.Compiler.Service/issues/79. | |||
There was a problem hiding this comment.
I guess the comments above can go now?
Uh oh!
There was an error while loading. Please reload this page.
| | DifferentGetterAndSetter(getValRef, setValRef) -> | ||
| let g = NicePrint.stringValOrMember displayEnv cenv.infoReader getValRef | ||
| let s = NicePrint.stringValOrMember displayEnv cenv.infoReader setValRef | ||
| $"{g}\n{s}" |
There was a problem hiding this comment.
Don't know if we have any consistent approach on that but maybe consider using Environment.NewLine
| if p.HasGetter && p.HasSetter then "with get, set" | ||
| elif p.HasGetter then "with get" | ||
| elif p.HasSetter then "with set" | ||
| else "" |
There was a problem hiding this comment.
I guess this shouldn't happen?
There was a problem hiding this comment.
No, that is unreachable code indeed.
| [<Test>] | ||
| let ``AutoProperty with get,set has two symbols`` () = | ||
| let ``AutoProperty with get,set has a single symbol!`` () = |
There was a problem hiding this comment.
Like the exclamation mark - feels like the emotional core of the PR :)
Related to #15586 and tries to address fsharp/fsharp-compiler-docs#79.
As mentioned in #15586, the
SynMemberDefn.AutoPropertywill be split into three parts when bothget,setare present.Consider the following example:
This will generate two bindings:
get_Yandset_Y.Both will currently use the
Yrange for the Item in NameResolution.When you later ask for the symbol use of
Y, you now get theget_YfromcheckResults.GetSymbolUseAtLocation.There is no clever symbol detection going on here,
https://github.com/dotnet/fsharp/blob/3570d5db878dcdace5c984bbca810a2bfa4ca4b4/src/Compiler/Service/FSharpCheckerResults.fs#L2825-L2827
it just returns the first value. Where actually two symbols were found.
In this PR, when both
get,setare present, the respectiveget_Yandset_Ymembers will now use the keyword (getorset) range for the NameResolution Item.And a new property Item will be reported for the range of
Y. That property will contain both the Getter and Setter:The same approach is possible for
SynMemberDefn.GetSetMemberwhere we can produce aItem.Propertyif both members are present.The result of this change is that
checkResults.GetSymbolUseAtLocationwill report a single symbol for the property name and not just return the getter. And this solves the original problem with the tooltip. And it also has a positive effect on the newGetValSignatureTextAPI.