From fa4dcfcfd5afe71ba9f4f2d5269cb3c7b07536d8 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Thu, 8 Feb 2024 12:40:49 +0000 Subject: [PATCH] Don't add property symbol for CLIEvent member. (#16658) * Don't add property symbol for CLIEvent member. * Add release notes --- .../.FSharp.Compiler.Service/8.0.300.md | 4 ++-- src/Compiler/Checking/CheckDeclarations.fs | 4 ++-- src/Compiler/SyntaxTree/SyntaxTreeOps.fs | 6 ++++++ src/Compiler/SyntaxTree/SyntaxTreeOps.fsi | 4 ++++ tests/service/Symbols.fs | 21 +++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md index a0cbc71e6fa..b3e2076bc21 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -5,8 +5,8 @@ * `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550)) * Graph Based Checking doesn't throw on invalid parsed input so it can be used for IDE scenarios ([PR #16575](https://github.com/dotnet/fsharp/pull/16575), [PR #16588](https://github.com/dotnet/fsharp/pull/16588), [PR #16643](https://github.com/dotnet/fsharp/pull/16643)) * Keep parens for problematic exprs (`if`, `match`, etc.) in `$"{(…):N0}"`, `$"{(…),-3}"`, etc. ([PR #16578](https://github.com/dotnet/fsharp/pull/16578)) -* Fix crash in DOTNET_SYSTEM_GLOBALIZATION_INVARIANT mode [#PR 16471](https://github.com/dotnet/fsharp/pull/16471)) - +* Fix crash in DOTNET_SYSTEM_GLOBALIZATION_INVARIANT mode ([PR #16471](https://github.com/dotnet/fsharp/pull/16471)) +* `[]` member should not produce property symbol. ([Issue #16640](https://github.com/dotnet/fsharp/issues/16640), [PR #16658](https://github.com/dotnet/fsharp/pull/16658)) ### Added diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index c5e21e744cd..ef59411179e 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -1140,11 +1140,11 @@ module MutRecBindingChecking = for b1, b2 in List.pairwise defnAs do match b1, b2 with | TyconBindingPhase2A.Phase2AMember { - SyntacticBinding = NormalizedBinding(pat = SynPat.Named(ident = SynIdent(ident = getIdent)); valSynData = SynValData(memberFlags = Some mf)) + SyntacticBinding = NormalizedBinding(pat = SynPat.Named(ident = SynIdent(ident = Get_OrSet_Ident & getIdent)); valSynData = SynValData(memberFlags = Some mf)) RecBindingInfo = RecursiveBindingInfo(vspec = vGet) }, TyconBindingPhase2A.Phase2AMember { - SyntacticBinding = NormalizedBinding(pat = SynPat.Named(ident = SynIdent(ident = setIdent))) + SyntacticBinding = NormalizedBinding(pat = SynPat.Named(ident = SynIdent(ident = Get_OrSet_Ident & setIdent))) RecBindingInfo = RecursiveBindingInfo(vspec = vSet) } when Range.equals getIdent.idRange setIdent.idRange -> match vGet.ApparentEnclosingEntity with diff --git a/src/Compiler/SyntaxTree/SyntaxTreeOps.fs b/src/Compiler/SyntaxTree/SyntaxTreeOps.fs index d6c65234237..a02591eb650 100644 --- a/src/Compiler/SyntaxTree/SyntaxTreeOps.fs +++ b/src/Compiler/SyntaxTree/SyntaxTreeOps.fs @@ -1062,3 +1062,9 @@ let (|TypesForTypar|) (t: SynType) = | _ -> continuation [ t ] visit id t + +[] +let (|Get_OrSet_Ident|_|) (ident: Ident) = + if ident.idText.StartsWithOrdinal("get_") then ValueSome() + elif ident.idText.StartsWithOrdinal("set_") then ValueSome() + else ValueNone diff --git a/src/Compiler/SyntaxTree/SyntaxTreeOps.fsi b/src/Compiler/SyntaxTree/SyntaxTreeOps.fsi index 5ee198564ed..6136886a3cc 100644 --- a/src/Compiler/SyntaxTree/SyntaxTreeOps.fsi +++ b/src/Compiler/SyntaxTree/SyntaxTreeOps.fsi @@ -355,3 +355,7 @@ val getTypeFromTuplePath: path: SynTupleTypeSegment list -> SynType list val (|MultiDimensionArrayType|_|): t: SynType -> (int * SynType * range) voption val (|TypesForTypar|): t: SynType -> SynType list + +/// Generated get_XYZ or set_XYZ ident text +[] +val (|Get_OrSet_Ident|_|): Ident -> unit voption diff --git a/tests/service/Symbols.fs b/tests/service/Symbols.fs index 42427a3a89b..a186b0b49f9 100644 --- a/tests/service/Symbols.fs +++ b/tests/service/Symbols.fs @@ -1214,3 +1214,24 @@ type T() = let i = 1 """ assertHasSymbolUsages ["i"] checkResults + +module Event = + [] + let ``CLIEvent member does not produce additional property symbol`` () = + let _, checkResults = getParseAndCheckResults """ +type T() = + [] + member this.Event = Event().Publish +""" + let allSymbols = + checkResults.GetSymbolUsesAtLocation(4, 21, " member this.Event = Event().Publish", [ "Event" ]) + + let hasPropertySymbols = + allSymbols + |> List.exists (fun su -> + match su.Symbol with + | :? FSharpMemberOrFunctionOrValue as mfv -> mfv.IsProperty + | _ -> false + ) + + Assert.False hasPropertySymbols