dotnet / dotnet/fsharp

Better diagnostics when using "as alias" in binding without wrapping expression in parens

Open
#5,259 6 comments 0 reactions 0 assignees View on GitHub
Area-Diagnostics Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

When giving alias via `as`, the first element of a tuple can be matched without wrapping it between parens, while the same doesn't work for any other items in the tuple.

```fsharp
let foo a b =
match a, b with
| Some _ as aa, None -> aa, None
| None, Some _ as bb -> None, bb // doesn't compile
```
> This expression was expected to have type ''a option' but here has type ''b option * 'c option'

if I wrap the second tuple element in the match in parens, it compiles:

```fsharp
let foo a b =
match a, b with
| Some _ as aa, None -> aa, None
| None, (Some _ as bb) -> None, bb
```

This seems to be inconsistent behaviour, failing principle of least surprise, and leading to confusing error message.

Is it according to spec or some issue that needs to be fixed? Should the parens be mandatory or optional in that case?

Reproduces in VS2015 and VS2017.

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.