dotnet / dotnet/fsharp

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

Aperta
#5,259 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Area-Diagnostics Feature Improvement
Lingua principale
F#
Stelle
4.3k
Fork
876
Merge medio
4g 8h
PR unite (30g)
133

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.