Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproductions of poor error messages #4314

Open
ayazhafiz opened this issue Oct 12, 2022 · 6 comments
Open

Reproductions of poor error messages #4314

ayazhafiz opened this issue Oct 12, 2022 · 6 comments
Labels
error-messages Related to the quality of error messages

Comments

@ayazhafiz
Copy link
Member

ayazhafiz commented Oct 12, 2022

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

@ayazhafiz ayazhafiz pinned this issue Oct 12, 2022
@ghigt
Copy link
Contributor

ghigt commented Oct 12, 2022

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
Copy link
Contributor

Reproduction

#4274
#4311

@brian-carroll
Copy link
Contributor

#4370

@benzen
Copy link

benzen commented Jan 9, 2024

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
Copy link

benzen commented Jan 9, 2024

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

────────────────────────────────────────────────────────────────────────────────

@lukewilliamboswell lukewilliamboswell added the error-messages Related to the quality of error messages label Aug 14, 2024
@nightingale-m
Copy link

nightingale-m commented Sep 7, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-messages Related to the quality of error messages
Projects
None yet
Development

No branches or pull requests

7 participants