Skip to content

Commit c0bbebd

Browse files
committed
Merge pull request #298 from 7sharp9/CurriedParametersForNestedFunctions
Added curried parameter groups for nested functions
2 parents 17447cd + 37ee1c8 commit c0bbebd

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

src/fsharp/vs/Symbols.fs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,21 @@ and FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
14021402

14031403
| V v ->
14041404
match v.ValReprInfo with
1405-
| None -> failwith "not a module let binding or member"
1405+
| None ->
1406+
let _, tau = v.TypeScheme
1407+
if isFunTy cenv.g tau then
1408+
let typeArguments, _typ = stripFunTy cenv.g tau
1409+
[ for typ in typeArguments do
1410+
let allArguments =
1411+
if isTupleTy cenv.g typ
1412+
then tryDestTupleTy cenv.g typ
1413+
else [typ]
1414+
yield
1415+
allArguments
1416+
|> List.map (fun arg -> FSharpParameter(cenv, arg, { Name=None; Attribs= [] }, x.DeclarationLocationOpt, false, false, false))
1417+
|> makeReadOnlyCollection ]
1418+
|> makeReadOnlyCollection
1419+
else makeReadOnlyCollection []
14061420
| Some (ValReprInfo(_typars,curriedArgInfos,_retInfo)) ->
14071421
let tau = v.TauType
14081422
let argtysl,_ = GetTopTauTypeInFSharpForm cenv.g curriedArgInfos tau range0

tests/service/ProjectAnalysisTests.fs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,3 +4325,63 @@ let ``Test project34 should report correct accessibility for System.Data.Listene
43254325
|> Option.get
43264326

43274327
listenerFuncEntity.Accessibility.IsPrivate |> shouldEqual true
4328+
4329+
module Project35 =
4330+
open System.IO
4331+
4332+
let fileName1 = Path.ChangeExtension(Path.GetTempFileName(), ".fs")
4333+
let base2 = Path.GetTempFileName()
4334+
let dllName = Path.ChangeExtension(base2, ".dll")
4335+
let projFileName = Path.ChangeExtension(base2, ".fsproj")
4336+
let fileSource1 = """
4337+
type Test =
4338+
let curriedFunction (one:int) (two:float) (three:string) =
4339+
one + int two + int three
4340+
let tupleFunction (one:int, two:float, three:string) =
4341+
one + int two + int three
4342+
"""
4343+
File.WriteAllText(fileName1, fileSource1)
4344+
let cleanFileName a = if a = fileName1 then "file1" else "??"
4345+
4346+
let fileNames = [fileName1]
4347+
let args = mkProjectCommandLineArgs (dllName, fileNames)
4348+
let options = checker.GetProjectOptionsFromCommandLineArgs (projFileName, args)
4349+
4350+
4351+
[<Test>]
4352+
let ``Test project35 CurriedParameterGroups should be available for nested functions`` () =
4353+
let wholeProjectResults = checker.ParseAndCheckProject(Project35.options) |> Async.RunSynchronously
4354+
let allSymbolUses = wholeProjectResults.GetAllUsesOfAllSymbols() |> Async.RunSynchronously
4355+
let findByDisplayName name =
4356+
Array.find (fun (su:FSharpSymbolUse) -> su.Symbol.DisplayName = name)
4357+
4358+
let curriedFunction = allSymbolUses |> findByDisplayName "curriedFunction"
4359+
match curriedFunction.Symbol with
4360+
| :? FSharpMemberOrFunctionOrValue as mfv ->
4361+
let curriedParamGroups =
4362+
mfv.CurriedParameterGroups
4363+
|> Seq.map Seq.toList
4364+
|> Seq.toList
4365+
match curriedParamGroups with
4366+
| [[param1];[param2];[param3]] ->
4367+
param1.Type.TypeDefinition.DisplayName |> should equal "int"
4368+
param2.Type.TypeDefinition.DisplayName |> should equal "float"
4369+
param3.Type.TypeDefinition.DisplayName |> should equal "string"
4370+
| _ -> failwith "Unexpected parameters"
4371+
| _ -> failwith "Unexpected symbol type"
4372+
4373+
let tupledFunction = allSymbolUses |> findByDisplayName "tupleFunction"
4374+
match tupledFunction.Symbol with
4375+
| :? FSharpMemberOrFunctionOrValue as mfv ->
4376+
let curriedParamGroups =
4377+
mfv.CurriedParameterGroups
4378+
|> Seq.map Seq.toList
4379+
|> Seq.toList
4380+
match curriedParamGroups with
4381+
| [[param1;param2;param3]] ->
4382+
param1.Type.TypeDefinition.DisplayName |> should equal "int"
4383+
param2.Type.TypeDefinition.DisplayName |> should equal "float"
4384+
param3.Type.TypeDefinition.DisplayName |> should equal "string"
4385+
| _ -> failwith "Unexpected parameters"
4386+
| _ -> failwith "Unexpected symbol type"
4387+

0 commit comments

Comments
 (0)