-
Notifications
You must be signed in to change notification settings - Fork 804
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 #15589
Report auto property #15589
Conversation
8b11472
to
1c40060
Compare
@nojaf Is there a chance that this change could also help to improve things for non-auto properties too? 😇 type T1() =
member x.P = 0
member x.P with set (i: int) = () type T2() =
member this.P
with get _ = 1
and set _ _ = () |
There's also seems to be a crazy way to mix auto properties with normal ones: type T3() =
member val P = 1
member this.P with set (i: int) = () |
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 |
Ready for review. |
5fec4c0
to
81b0fc6
Compare
Co-authored-by: dawe <dawedawe@posteo.de>
@@ -9035,15 +9035,17 @@ FSharp.Compiler.Syntax.SynUnionCaseKind: FSharp.Compiler.Syntax.SynUnionCaseKind | |||
FSharp.Compiler.Syntax.SynUnionCaseKind: Int32 Tag | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one in particular is a bit more scary to me.
@0101 @auduchinok @T-Gro please take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one in particular is a bit more scary to me.
@0101 @auduchinok @T-Gro please take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few remarks, mostly minor things and some learning opportunities for me.
Thanks a lot!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the comments above can go now?
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this shouldn't happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that is unreachable code indeed.
@@ -458,19 +464,290 @@ type Foo = | |||
| symbol -> Assert.Fail $"Expected {symbol} to be FSharpMemberOrFunctionOrValue" | |||
|
|||
[<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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.AutoProperty
will be split into three parts when bothget,set
are present.Consider the following example:
This will generate two bindings:
get_Y
andset_Y
.Both will currently use the
Y
range for the Item in NameResolution.When you later ask for the symbol use of
Y
, you now get theget_Y
fromcheckResults.GetSymbolUseAtLocation
.There is no clever symbol detection going on here,
fsharp/src/Compiler/Service/FSharpCheckerResults.fs
Lines 2825 to 2827 in 3570d5d
it just returns the first value. Where actually two symbols were found.
In this PR, when both
get,set
are present, the respectiveget_Y
andset_Y
members will now use the keyword (get
orset
) 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.GetSetMember
where we can produce aItem.Property
if both members are present.The result of this change is that
checkResults.GetSymbolUseAtLocation
will 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 newGetValSignatureText
API.