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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/8.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Fix crash in DOTNET_SYSTEM_GLOBALIZATION_INVARIANT mode ([PR #16471](https://github.com/dotnet/fsharp/pull/16471))
* `[<CliEvent>]` member should not produce property symbol. ([Issue #16640](https://github.com/dotnet/fsharp/issues/16640), [PR #16658](https://github.com/dotnet/fsharp/pull/16658))
* Fix discriminated union initialization. ([#PR 16661](https://github.com/dotnet/fsharp/pull/16661))
* Allow calling method with both Optional and ParamArray. ([#PR 16688](https://github.com/dotnet/fsharp/pull/16688), [suggestions #1120](https://github.com/fsharp/fslang-suggestions/issues/1120))

### Added

Expand Down
6 changes: 6 additions & 0 deletions src/Compiler/Checking/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,12 @@ type CalledMeth<'T>
let nUnnamedCalledArgs = unnamedCalledArgs.Length
if allowOutAndOptArgs && nUnnamedCallerArgs < nUnnamedCalledArgs then
let unnamedCalledArgsTrimmed, unnamedCalledOptOrOutArgs = List.splitAt nUnnamedCallerArgs unnamedCalledArgs

// take the last ParamArray arg out, make it not break the optional/out params check
let unnamedCalledArgsTrimmed, unnamedCalledOptOrOutArgs =
match List.rev unnamedCalledOptOrOutArgs with
| h :: t when h.IsParamArray -> unnamedCalledArgsTrimmed @ [h], List.rev t
| _ -> unnamedCalledArgsTrimmed, unnamedCalledOptOrOutArgs

let isOpt x = x.OptArgInfo.IsOptional
let isOut x = x.IsOutArg && isByrefTy g x.CalledArgumentType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,34 @@ let _, _ = Thing.Do()
(Error 501, Line 6, Col 12, Line 6, Col 22, "The member or object constructor 'Do' takes 1 argument(s) but is here given 0. The required signature is 'static member Thing.Do: [<Optional>] i: outref<bool> -> bool'.")
]

[<Fact>]
let ``optional and ParamArray parameter resolves correctly `` () =
Fsx """
open System.Runtime.InteropServices

type Thing =
static member Do(
[<Optional; DefaultParameterValue "">] something: string,
[<System.ParamArray>] args: obj[]) = something, args
static member Do2(
[<Optional; DefaultParameterValue "">] something: string,
outvar: outref<int>,
[<System.ParamArray>] args: obj[]) =

outvar <- 1
something, args
let _, _ = Thing.Do()
let _, _ = Thing.Do("123")
let _, _ = Thing.Do("123", 1, 2, 3, 4)

let _, _ = Thing.Do2()
let _, _ = Thing.Do2("123")
let _ =
let mutable x = 0
Thing.Do2("123", &x)
let _ =
let mutable x = 0
Thing.Do2("123", &x, 1, 2, 3, 4)
"""
|> typecheck
|> shouldSucceed