Inference error shadows additional error
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
Consider the following code:
```fsharp
let greyscaleGradient minimum maximum numberOfItems : int seq =
if numberOfItems > 1 then
let step = (maximum - minimum) / (numberOfItems - 1)
let calculatedValues = seq {for n in 0..(numberOfItems-2) -> n * step}
Seq.append calculatedValues (seq {maximum})
else
seq {minimum}
```
This is a compile error because `seq{maximum}` is inferred causes `maximum` to be of type `unit`, but we're expecting an `int seq`.
However, this also hides an error on this line:
```fsharp
let step = (maximum - minimum) / (numberOfItems - 1)
```
So you might be misled into thinking that the issue is somewhere else, since the compiler appears to be okay with that line. Only when you over over it will you be led into more confusion:

Instead, if the error were not "shadowed", it might lead you to placing a `yield` in the first `seq` expression instead, which fixes the compile error.
I suppose it's a separate problem that `seq{maximum}` changes `maximum` from an `int` into a `unit` even though it's clearly being used to subtract from 2 lines earlier.
Contributor guide
Assessment
This issue has not been assessed yet.