Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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/11.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
* Fix nativeptr in interfaces leads to TypeLoadException. (Issue [#14508](https://github.com/dotnet/fsharp/issues/14508), [PR #19338](https://github.com/dotnet/fsharp/pull/19338))
* Fix box instruction for literal upcasts. (Issue [#18319](https://github.com/dotnet/fsharp/issues/18319), [PR #19338](https://github.com/dotnet/fsharp/pull/19338))
* Fix Decimal Literal causes InvalidProgramException in Debug builds. (Issue [#18956](https://github.com/dotnet/fsharp/issues/18956), [PR #19338](https://github.com/dotnet/fsharp/pull/19338))
* Report a self identifier named `__` (as in `member __.M()`) to editor tooling. Only its uses were reported, not its declaration, so Rename rewrote the body of such a member and left `member __.` behind. The self identifier synthesized by the auto-property desugaring, which the name check was really aimed at, is now suppressed by its synthetic range instead. ([Issue #20566](https://github.com/dotnet/fsharp/issues/20566), [PR #20598](https://github.com/dotnet/fsharp/pull/20598))
* Fix `AttributeUsage.AllowMultiple` not being inherited for attributes subclassed in C#. ([Issue #17107](https://github.com/dotnet/fsharp/issues/17107), [PR #19315](https://github.com/dotnet/fsharp/pull/19315))
* Fix signature generation: recursive module `do` binding leaking compiler-generated val. ([Issue #13832](https://github.com/dotnet/fsharp/issues/13832), [PR #19586](https://github.com/dotnet/fsharp/pull/19586))
* Fix signature generation: literal values in attribute arguments now preserve literal identifier name. ([Issue #13810](https://github.com/dotnet/fsharp/issues/13810), [PR #19586](https://github.com/dotnet/fsharp/pull/19586))
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4841,7 +4841,7 @@ 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.MakeSynthetic())
let headPatIds = if isStatic then [id] else [ident ("__", mMemberPortion);id]
let headPatIds = if isStatic then [id] else [ident ("__", mMemberPortion.MakeSynthetic());id]
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 Down
10 changes: 3 additions & 7 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,13 +1451,9 @@ let MakeAndPublishVal (cenv: cenv) env (altActualParent, inSig, declKind, valRec

let shouldNotifySink (vspec: Val) =
match vspec.MemberInfo with
// `this` reference named `__`. It's either:
// * generated by compiler for auto properties or
// * provided by source code (i.e. `member _.Method = ...`)
// We don't notify sink about it to prevent generating `FSharpSymbol` for it and appearing in completion list.
| None when
vspec.IsBaseVal ||
vspec.IsMemberThisVal && vspec.LogicalName = "__" -> false
// visualfsharp#3699: the range of `base` spans the whole `inherit` expression, so reporting it
// makes its environment the most deeply nested one at the constructor arguments, shadowing theirs.
| None when vspec.IsBaseVal -> false
| _ -> true

match cenv.tcSink.CurrentSink with
Expand Down
44 changes: 44 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,50 @@ type Foo =
let backingFieldSymbols = allMfvs |> List.filter (fun mfv -> mfv.DisplayName.Contains("@"))
Assert.True(backingFieldSymbols.IsEmpty, $"Compiler-generated backing field should not appear, but found: {backingFieldSymbols |> List.map (fun m -> m.DisplayName)}")

let private selfIdentifierRanges (checkResults: FSharpCheckFileResults) =
checkResults.GetAllUsesOfAllSymbolsInFile()
|> Seq.filter (fun su ->
match su.Symbol with
| :? FSharpMemberOrFunctionOrValue as mfv -> mfv.IsMemberThisValue
| _ -> false)
|> Seq.map _.Range
|> Seq.sortBy (fun m -> m.StartLine, m.StartColumn)
|> Seq.toList

[<Theory>]
[<InlineData "this">]
[<InlineData "self">]
[<InlineData "__">]
let ``Self identifier is reported at its declaration and at its uses`` (selfId: string) =
let _, checkResults = getParseAndCheckResults $"""
namespace Foo

type Foo() =
member {selfId}.M() = {selfId}.N()
member {selfId}.N() = 1
"""
let n = selfId.Length

match selfIdentifierRanges checkResults with
| [ mDeclInM; mUseInM; mDeclInN ] ->
assertRange (5, 11) (5, 11 + n) mDeclInM
assertRange (5, 18 + n) (5, 18 + 2 * n) mUseInM
assertRange (6, 11) (6, 11 + n) mDeclInN
| ranges -> failwith $"Expected three self identifier symbol uses, got %A{ranges}"

[<Fact>]
let ``AutoProperty does not expose its compiler-generated self identifier`` () =
let _, checkResults = getParseAndCheckResults """
namespace Foo

type Foo =
member val AutoPropGetSet = 0 with get, set
"""
// The synthesized `__` sits on the property name's range, so reporting it would shadow the property
match selfIdentifierRanges checkResults with
| [] -> ()
| ranges -> failwith $"Expected no self identifier symbol uses, got %A{ranges}"

[<Fact>]
let ``Property symbol is resolved for property`` () =
let symbols = Checker.getSymbolUses """
Expand Down
Loading