@@ -5,6 +5,26 @@ open Xunit
55open FSharp.Test
66open FSharp.Test .Compiler
77
8+ let private getGenericParametersNamesFor
9+ ( cUnit : CompilationUnit )
10+ ( entityDisplayName : string )
11+ ( valueDisplayName : string )
12+ ( additionalFile : SourceCodeFileKind )
13+ : string array =
14+ let typeCheckResult =
15+ cUnit |> withAdditionalSourceFile additionalFile |> typecheckProject
16+
17+ typeCheckResult.AssemblySignature.Entities
18+ |> Seq.tryPick ( fun ( entity : FSharpEntity ) ->
19+ if entity.DisplayName <> entityDisplayName then
20+ None
21+ else
22+ entity.MembersFunctionsAndValues
23+ |> Seq.tryFind ( fun mfv -> mfv.DisplayName = valueDisplayName)
24+ |> Option.map ( fun ( mfv : FSharpMemberOrFunctionOrValue ) ->
25+ mfv.GenericParameters |> Seq.map ( fun gp -> gp.DisplayName) |> Seq.toArray))
26+ |> Option.defaultValue Array.empty
27+
828[<Fact>]
929let ``The call site of a generic function should have no influence on the name of the type parameters`` () =
1030 let definitionFile =
@@ -26,26 +46,8 @@ let otherGenericFunction _ _ _ =
2646 |> FsSource)
2747 .WithFileName( " B.fs" )
2848
29- let getGenericParametersNamesFor
30- ( entityDisplayName : string )
31- ( valueDisplayName : string )
32- ( additionalFile : SourceCodeFileKind )
33- : string array =
34- let typeCheckResult =
35- definitionFile |> withAdditionalSourceFile additionalFile |> typecheckProject
36-
37- typeCheckResult.AssemblySignature.Entities
38- |> Seq.tryPick ( fun ( entity : FSharpEntity ) ->
39- if entity.DisplayName <> entityDisplayName then
40- None
41- else
42- entity.MembersFunctionsAndValues
43- |> Seq.tryFind ( fun mfv -> mfv.DisplayName = valueDisplayName)
44- |> Option.map ( fun ( mfv : FSharpMemberOrFunctionOrValue ) ->
45- mfv.GenericParameters |> Seq.map ( fun gp -> gp.DisplayName) |> Seq.toArray))
46- |> Option.defaultValue Array.empty
47-
48- let namesForB = getGenericParametersNamesFor " A" " someGenericFunction" usageFile
49+ let namesForB =
50+ getGenericParametersNamesFor definitionFile " A" " someGenericFunction" usageFile
4951
5052 let alternativeUsageFile =
5153 ( """
@@ -58,6 +60,31 @@ let alternateGenericFunction _ =
5860 .WithFileName( " C.fs" )
5961
6062 let namesForC =
61- getGenericParametersNamesFor " A" " someGenericFunction" alternativeUsageFile
63+ getGenericParametersNamesFor definitionFile " A" " someGenericFunction" alternativeUsageFile
6264
6365 Assert.Equal< string array>( namesForB, namesForC)
66+
67+ [<Fact>]
68+ let ``Fixed typar name in signature file is still respected`` () =
69+ let signatureFile =
70+ Fsi
71+ """
72+ module A
73+
74+ val someGenericFunction: 'x -> unit
75+ """
76+ |> withFileName " A.fsi"
77+
78+ let implementationFile =
79+ ( """
80+ module A
81+
82+ let someGenericFunction _ = ()
83+ """
84+ |> FsSource)
85+ .WithFileName( " A.fs" )
86+
87+ let names =
88+ getGenericParametersNamesFor signatureFile " A" " someGenericFunction" implementationFile
89+
90+ Assert.Equal< string array>([| " x" |], names)
0 commit comments