dotnet / dotnet/fsharp

Confusing error message when missing parentheses in let-bound pattern match and tree structure

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

Description

Consider the following:

```fsharp
type T = Node of T *T
module T =
let f t =
let Node(l, r) = t
l, r |> ignore
```

**Expected:**

This either:

* Works just fine
* Gives an error at the `let Node(l, r)` site

**Actual:**

This gives an error on `l` and `r` saying they're undefined:

image

The fix is to wrap the let-bound pattern match in parentheses:

```fsharp
type T = Node of T *T
module T =
let f t =
let (Node(l, r)) = t
l, r |> ignore
```

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.