-
Notifications
You must be signed in to change notification settings - Fork 815
[<System.ParamArray>]
parameter in member function causes type check error.
#17957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Probably a duplicate of #11918. I think it's a type inference + overload resolution thing: a method with a single parameter annotated with But there is not perfect symmetry in how overload resolution works for directly-invoked methods and methods used in a first-class way (e.g., with piping). See #11918 (comment). |
The error message is confusing, though: > open System
-
- type T =
- static member M ([<ParamArray>] xs : int array) = xs
-
- let xs = [|1..10|]
-
- xs |> T.M;;
xs |> T.M;;
------^^^
stdin(8,7): error FS0001: This expression was expected to have type
'int array'
but here has type
'unit' It sounds like the opposite of what the source code looks like. Especially since this works: () |> T.M |
It is same situation for optional parameters. And this only occurs when the method doesn't have overloads. type X () =
member _.ID ([<System.ParamArray>] arr) = arr
// another overload
member _.ID (x: int) = x
member _.OptionalParameter (?x: int) = x
let x = X()
// will not fail
[| 1; 2; 3 |] |> x.ID
// will fail
1 |> x.OptionalParameter There is a comment say the optional and fsharp/src/Compiler/Checking/Expressions/CheckExpressions.fs Lines 9944 to 9947 in 5065f5b
|
When I use the parameter of
[<ParamArray>]
attribute in member function, I cannot pass the parameter using pipeline operator:And no type check error occurs when the
[<ParamArray>]
attribute is not used or using[<ParamArray>]
at the top level:Why does
[<ParamArray>]
behave differently in member functions? Is this a compiler bug?The text was updated successfully, but these errors were encountered: