gleam
gleam copied to clipboard
Confusing error message for a not exhaustive pattern match in a let statement
When a pattern in a let statement is not statically guaranteed to match, the error message tells that this is a case statement, which is confusing.
fn a_function() {
let result = Ok(1)
let Ok(value) = result
}
error: Not exhaustive pattern match
┌─ ./src/example/example.gleam:3:3
│
3 │ let Ok(value) = result
│ ^^^^^^^^^^^^^^^^^^^^^^
This case expression does not match all possibilities. Each constructor
must have a pattern that matches it or else it could crash.
These values are not matched:
- Error
Thank you
Here's where the error is defined. The message was a bit more general but was changed to mention "case expression" in https://github.com/gleam-lang/gleam/commit/a8340ba909b64ed26a1d1604fdb936677b1978f6 . Here is where it is reported for let/assert and here is where it is reported for case. To fix this could be either converted to two separate error variants, or the NotExhaustivePatternMatch
error variant could carry additional information as to where it came from, and then the message would be returned appropriately.
I think having an additional field on the error sounds good as it'll be otherwise be the same.