roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.1k stars 289 forks source link

Reproductions of poor error messages #4314

Open ayazhafiz opened 1 year ago

ayazhafiz commented 1 year ago

We have some projects around improving the quality of error messages in type mismatches:

This issue is a bulletin board to collect reproductions of poor error messages so that we have test cases for improvements!

When listing a reproduction, please title your comment with # Reproduction (so that it stands out) and please provide a minimal reproduction of the test case! If your reproduction comes from another issue, you can instead link to that issue.

Examples:

Reproduction comment # Reproduction Code: ``` » X : [A Str, B Str] … … x : Result X [] … x = … if True then Ok (A "") else Ok (B "") … … when x is … Ok A -> "" … Ok B -> "" ``` Error message: ``` ── TYPE MISMATCH ─────────────────────────────────────────────────────────────── The branches of this when expression don't match the condition: 10│> when x is 11│ Ok A -> "" 12│ Ok B -> "" This x value is a: Result X [] But the branch patterns have type: [Ok [A, B]] The branches must be cases of the when condition's type! ```
Reproduction comment linking to issue # Reproduction #4007
ghigt commented 1 year ago

Reproduction

Code:

app "main"
    packages { pf: "./roc/examples/cli/cli-platform/main.roc" }
    imports [pf.Program, pf.Stdout, pf.Task]
    provides [main] to pf

main =
    Task.attempt processTask \p ->
        when p is
            Ok s -> Stdout.line s
            Err ReadErr -> Stdout.line "Tried to read"
            # Err WriteErr -> Stdout.line "Tried to write"

    |> Program.quick

processTask : Task.Task Str [ReadErr, WriteErr] []*

Error message:


── TYPE MISMATCH ──────────────────────────────────────────────────── test.roc ─

This 2nd argument to attempt has an unexpected type:

 7│>      Task.attempt processTask \p ->
 8│>          when p is
 9│>              Ok s -> Stdout.line s
10│>              Err ReadErr -> Stdout.line "Tried to read"

The argument is an anonymous function of type:

    [Err [ReadErr], Ok Str] -> Task {} * [Write [Stdout]*]* ?

But attempt needs its 2nd argument to be:

    Result Str [ReadErr, WriteErr] -> Task {} * [Write [Stdout]*]* ?

────────────────────────────────────────────────────────────────────────────────
cjduncana commented 1 year ago

Reproduction

4274

4311

brian-carroll commented 1 year ago

4370

benzen commented 8 months ago

Reproduction

app "hello-world"
    packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.1/Icc3xJoIixF3hCcfXrDwLCu4wQHtNdPyoJkEbkgIElA.tar.br" }
    imports [pf.Stdout]
    provides [main] to pf

filterNumbers = \ line ->
  line
  |> Str.graphemes
  |> List.keepIf \ graphem -> List.contains numbers, graphem

main = Stdout.line "hello"
thread 'main' panicked at 'not yet implemented: unhandled parse error: Pattern(IndentEnd(@523), @515)', crates/reporting/src/error/parse.rs:690:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

And the compiler hang also

benzen commented 8 months ago

Reproduction

filterNumbers = \ line ->
  line
  |> Str.graphemes
  |> List.keepIf List.contains numbers, g
  |> Str.joinWith "\n"
── UNRECOGNIZED NAME ──────────────────────────────────────────────── main.roc ─

Nothing is named `g` in this scope.

23│    |> List.keepIf (\ g -> List.contains numbers, g)
                                                     ^

Did you mean one of these?

    U8
    Eq
    I8
    Ok

────────────────────────────────────────────────────────────────────────────────
nightingale-m commented 5 days ago

Reproduction

Code:

collatzStep = \number, stepCount ->
    if number == 1 then
        (number, stepCount)
    # else
    if Num.isEven number then
        collatzStep (number // 2) (stepCount + 1)
    else
        collatzStep (number * 3 + 1) (stepCount + 1)

Error message:

── STATEMENT AFTER EXPRESSION in CollatzConjecture.roc ─────────────────────────

I just finished parsing an expression with a series of definitions,

and this line is indented as if it's intended to be part of that
expression:

         ^

However, I already saw the final expression in that series of
definitions.