Skip to content

Commit a653791

Browse files
committed
Merge pull request #309 from 7sharp9/ReturnParameter
Add support for ReturnParameter in nested functions
2 parents 6db431a + 4666ce8 commit a653791

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/fsharp/vs/Symbols.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,13 @@ and FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
14531453
FSharpParameter(cenv, rty, retInfo, x.DeclarationLocationOpt, isParamArrayArg=false, isOutArg=false, isOptionalArg=false)
14541454
| V v ->
14551455
match v.ValReprInfo with
1456-
| None -> failwith "not a module let binding or member"
1456+
| None ->
1457+
let _, tau = v.TypeScheme
1458+
if isFunTy cenv.g tau then
1459+
let _typeArguments, rty = stripFunTy cenv.g tau
1460+
FSharpParameter(cenv, rty, { Name=None; Attribs= [] }, x.DeclarationLocationOpt, isParamArrayArg=false, isOutArg=false, isOptionalArg=false)
1461+
else
1462+
failwith "not a module let binding or member"
14571463
| Some (ValReprInfo(_typars,argInfos,retInfo)) ->
14581464

14591465
let tau = v.TauType

tests/service/ProjectAnalysisTests.fs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4336,9 +4336,9 @@ module Project35 =
43364336
let fileSource1 = """
43374337
type Test =
43384338
let curriedFunction (one:int) (two:float) (three:string) =
4339-
one + int two + int three
4339+
float32 (one + int two + int three)
43404340
let tupleFunction (one:int, two:float, three:string) =
4341-
one + int two + int three
4341+
float32 (one + int two + int three)
43424342
"""
43434343
File.WriteAllText(fileName1, fileSource1)
43444344
let cleanFileName a = if a = fileName1 then "file1" else "??"
@@ -4356,32 +4356,49 @@ let ``Test project35 CurriedParameterGroups should be available for nested funct
43564356
Array.find (fun (su:FSharpSymbolUse) -> su.Symbol.DisplayName = name)
43574357

43584358
let curriedFunction = allSymbolUses |> findByDisplayName "curriedFunction"
4359+
43594360
match curriedFunction.Symbol with
43604361
| :? FSharpMemberOrFunctionOrValue as mfv ->
4362+
43614363
let curriedParamGroups =
43624364
mfv.CurriedParameterGroups
43634365
|> Seq.map Seq.toList
43644366
|> Seq.toList
4367+
4368+
//check the parameters
43654369
match curriedParamGroups with
43664370
| [[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"
4371+
param1.Type.TypeDefinition.DisplayName |> shouldEqual "int"
4372+
param2.Type.TypeDefinition.DisplayName |> shouldEqual "float"
4373+
param3.Type.TypeDefinition.DisplayName |> shouldEqual "string"
43704374
| _ -> failwith "Unexpected parameters"
4375+
4376+
//now check the return type
4377+
let retTyp = mfv.ReturnParameter
4378+
retTyp.Type.TypeDefinition.DisplayName |> shouldEqual "float32"
4379+
43714380
| _ -> failwith "Unexpected symbol type"
43724381

43734382
let tupledFunction = allSymbolUses |> findByDisplayName "tupleFunction"
43744383
match tupledFunction.Symbol with
43754384
| :? FSharpMemberOrFunctionOrValue as mfv ->
4385+
43764386
let curriedParamGroups =
43774387
mfv.CurriedParameterGroups
43784388
|> Seq.map Seq.toList
43794389
|> Seq.toList
4390+
4391+
//check the parameters
43804392
match curriedParamGroups with
43814393
| [[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"
4394+
param1.Type.TypeDefinition.DisplayName |> shouldEqual "int"
4395+
param2.Type.TypeDefinition.DisplayName |> shouldEqual "float"
4396+
param3.Type.TypeDefinition.DisplayName |> shouldEqual "string"
43854397
| _ -> failwith "Unexpected parameters"
4398+
4399+
//now check the return type
4400+
let retTyp = mfv.ReturnParameter
4401+
retTyp.Type.TypeDefinition.DisplayName |> shouldEqual "float32"
4402+
43864403
| _ -> failwith "Unexpected symbol type"
43874404

0 commit comments

Comments
 (0)