dotnet / dotnet/fsharp

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

未关闭
#5,259 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Area-Diagnostics Feature Improvement
主要语言
F#
星标
4.3k
派生
876
平均合并
4 天 8 小时
30 天内合并 PR
133

描述

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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。