Skip to content

[<System.ParamArray>] parameter in member function causes type check error. #17957

@muqiuhan

Description

@muqiuhan

When I use the parameter of [<ParamArray>] attribute in member function, I cannot pass the parameter using pipeline operator:

> type X () = member _.ID ([<System.ParamArray>] arr) = arr;;
type X =
  new: unit -> X
  member ID: [<System.ParamArray>] arr: 'a -> 'a

> let x = X();;                                              
val x: X

> x.ID([| 1; 2; 3 |]);;                                      
val it: int array = [|1; 2; 3|]

> [| 1; 2; 3 |] |> x.ID;;

  [| 1; 2; 3 |] |> x.ID;;
  -----------------^^^^
/home/muqiu/stdin(10,18): error FS0001: This expression was expected to have type
    'int array'    
but here has type
    'unit'

And no type check error occurs when the [<ParamArray>] attribute is not used or using [<ParamArray>] at the top level:

> type X () = member _.ID (arr) = arr;;
type X =
  new: unit -> X
  member ID: arr: 'a -> 'a

> let x = X();;                        
val x: X

> [| 1; 2; 3 |] |> x.ID;;
val it: int array = [|1; 2; 3|]

> let ID ([<System.ParamArray>] arr) = arr;;     
val ID: [<System.ParamArray>] arr: 'a -> 'a

> [| 1; 2; 3 |] |> ID;;                     
val it: int array = [|1; 2; 3|]

Why does [<ParamArray>] behave differently in member functions? Is this a compiler bug?

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions