dotnet / dotnet/fsharp

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

Open
#17,957 3 comments 1 reaction 0 assignees View on GitHub
Area-Compiler-Checking Feature Improvement help wanted Triage-Investigate
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

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

```fsharp
> type X () = member _.ID ([] arr) = arr;;
type X =
new: unit -> X
member ID: [] 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 `[]` attribute is not used or using `[]` at the top level:
```fsharp
> 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 ([] arr) = arr;;
val ID: [] arr: 'a -> 'a

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

Why does `[]` behave differently in member functions? Is this a compiler bug?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.