dotnet / dotnet/fsharp

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

オープン
#5,259 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る
Area-Diagnostics Feature Improvement
主要言語
F#
スター
4.3k
フォーク
876
平均マージ
4日 8時間
マージ済み PR(30日)
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 を短くまとめたダイジェスト。