From 790ee8dc54b32cd53d5d5966ce5e46cd4d87e449 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 1 Jun 2023 11:30:29 +0200 Subject: [PATCH 1/2] Reuse synTypar names when typar is resolved. --- src/Compiler/Checking/CheckDeclarations.fs | 12 +++++++++++- .../Signatures/TypeTests.fs | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 3c97ea8354e..d4c15029ff0 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -3948,7 +3948,17 @@ module TcDeclarations = let resInfo = TypeNameResolutionStaticArgsInfo.FromTyArgs synTypars.Length let _, tcref = match ResolveTypeLongIdent cenv.tcSink cenv.nameResolver ItemOccurence.Binding OpenQualified envForDecls.NameEnv ad longPath resInfo PermitDirectReferenceToGeneratedType.No with - | Result res -> res + | Result res -> + // Update resolved type parameters with the names from the source. + let _, tcref = res + if tcref.TyparsNoRange.Length = synTypars.Length then + (tcref.TyparsNoRange, synTypars) + ||> List.zip + |> List.iter (fun (typar, SynTyparDecl.SynTyparDecl(_, SynTypar(ident = untypedIdent))) -> + typar.SetIdent(untypedIdent) + ) + + res | res when inSig && List.isSingleton longPath -> errorR(Deprecated(FSComp.SR.tcReservedSyntaxForAugmentation(), m)) ForceRaise res diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs index d7f81a04f50..1014a4249c2 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs @@ -75,3 +75,20 @@ namespace Foo.Types val EndLine: int val EndColumn: int""" + +[] +let ``Type extension uses type parameters names from source`` () = + FSharp """ +module Extensions + +type List<'E> with + + member this.X = this.Head +""" + |> printSignatures + |> should equal + """ +module Extensions +type List<'E> with + + member X: 'E""" From 7f4feaa472977ba1dc6b5910ff1c948cf982b3a9 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 1 Jun 2023 11:37:58 +0200 Subject: [PATCH 2/2] Add additional tests. --- .../Signatures/TypeTests.fs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs b/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs index 1014a4249c2..0bf215a0dfd 100644 --- a/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs @@ -92,3 +92,43 @@ module Extensions type List<'E> with member X: 'E""" + +[] +let ``Type extension with constraints uses type parameters names from source`` () = + FSharp """ +module Extensions + +type Map<'K, 'V when 'K: comparison> with + + member m.X (t: 'T) (k: 'K) = Some k, ({| n = [|k|] |}, 0) +""" + |> printSignatures + |> should equal + """ +module Extensions +type Map<'K,'V when 'K: comparison> with + + member X: t: 'T -> k: 'K -> 'K option * ({| n: 'K array |} * int) when 'K: comparison""" + +[] +let ``Type extension with lowercase type parameters names from source`` () = + FSharp """ +module Extensions + +open System.Collections.Concurrent + +type ConcurrentDictionary<'key, 'value> with + + member x.TryFind key = + match x.TryGetValue key with + | true, value -> Some value + | _ -> None +""" + |> printSignatures + |> should equal + """ +module Extensions +type System.Collections.Concurrent.ConcurrentDictionary<'key,'value> with + + member TryFind: key: 'key -> 'value option""" + \ No newline at end of file