dotnet / dotnet/fsharp

Improve Error Reporting: The value or constructor is not defined.

Open
#6,677 0 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 a function is defined after the usage, there is an error `error FS0039: The value or constructor 'X' is not defined`

That's ok, but should help more, if the function is defined somewhere near

#### Repro steps

```fsharp
[]
let main argv =
printfn "Hello World from F#!"
add 1 2
0 // return an integer exit code

let add x y =
x + y
```

give as error

```
Program.fs(8,5): error FS0039: The value or constructor 'add' is not defined. [my.fsproj]
```

#### Expected behavior

Help user understand the function is defined in the wrong place, like

```
The value or constructor 'add' is not defined. There is a function `add` defined later, but functions should be defined before usage in F#.
```

or at least something like (dunno how to write that better)

```
The value or constructor 'add' is not defined. The 'add' value (like a functions or a binding) or constructor should be defined before usage.
```

#### Actual behavior

Correct, but error message can help more

### Additional info

ref https://github.com/Microsoft/visualfsharp/issues/1103

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.