Skip to content
Merged
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
12 changes: 11 additions & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/Signatures/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,60 @@ namespace Foo.Types
val EndLine: int

val EndColumn: int"""

[<Fact>]
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"""

[<Fact>]
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"""

[<Fact>]
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"""