compiler icon indicating copy to clipboard operation
compiler copied to clipboard

I cannot find a `return` variable better error message

Open aminnairi opened this issue 3 years ago • 1 comments

Quick Summary:

New Elm developers comming from JavaScript and other languages that have a return keyword may be confused when the return keyword is not needed in functions, or may keep the habit of using it in Elm programs.

It would be great to have a better error message for cases when the return keyword is used in front of an expression that may be returned by a function.

Actually, the error message looks like this.

I cannot find a `return` variable:

7|     return ( after - before ) / before
       ^^^^^^
These names seem close though:

    turns
    after
    atan
    before

Hint: Read <https://elm-lang.org/0.19.1/imports> to see how `import`
declarations work in Elm.

This can be improved, especially with a hint message when the return keyword is detected, something like

I cannot find a `return` variable:

7|     return ( after - before ) / before
       ^^^^^^
These names seem close though:

    turns
    after
    atan
    before

Hint: There is no return keyword in Elm, this is because functions always have
a return value and the last expression is what the function sends the the
caller, so it is not necessary to use in your function. This makes the code
terse and more readable and you wont forget to return a value in your
functions! Read more here <https://some.link/to/doc>

SSCCE

module Main exposing (main)

import Html


getEvolutionRate before after =
    return ( after - before ) / before


main =
    Html.text ( String.fromFloat ( getEvolutionRate 38000 45000 ) )
  • Elm: 0.19.1
  • Browser: Google Chrome
  • Operating System: Arch Linux

Additional Details

The error message is not what I want in the end but is an inspiration I got in the moment.

aminnairi avatar Aug 18 '22 17:08 aminnairi

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

Finally, please be patient with the core team. They are trying their best with limited resources.

github-actions[bot] avatar Aug 18 '22 17:08 github-actions[bot]