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

Record definition whitespace #255

snewell92 opened this issue Mar 11, 2018 · 1 comment


Copy link

commented Mar 11, 2018

Consider the following elm program that does nothing but fail to compile:

type alias Stuff = {
    a : String,
    bananas : Int

myStuff : Stuff
myStuff = {
    a = "Hi",
    bananas = 5

Compiler error says:

I need whitespace, but got stuck on what looks like a new declaration. You are
either missing some stuff in the declaration above or just need to add some
spaces here:

This is definitely a correct error message ✔️, but it doesn't necessarily clearly explain why to new comers (ie me), and in the spirit of improving the error messages I'd like to submit this reasoning:

In some areas in the docs about records it would seem that records aren't indentation or white-space sensitive, but maybe the error message could give an example of a style-guide-conforming record definition, like this:

myStuff : Stuff
myStuff =
    { a = "Hi"
    , bananas = 5

And perhaps a link, reference, or a short blurb on the reasoning about this, or maybe just something like "record definitions like this example one are definitively unambiguous, and sticking to it will ensure your program is readable by other elm programmers and quickly compilable"..? 😕

Idk, maybe it's a non issue, feel free to close since the existing error message does mention white-space, which is what is needed to change to clear the error, I just spent a few minute fighting the compiler on it though.

One thing that's interesting is the type alias definition compiles fine, but to get the record definition to work you just need to add at least one space on the last line.

@evancz evancz added the parser label Jul 25, 2019


This comment has been minimized.

Copy link

commented Jul 26, 2019

I am finishing up an overhaul of the parser that makes it easier to give more precise error messages for syntax problems. This report encouraged me to make one last tweak in elm/compiler@11ffbf5 so my development build is now giving the following message for your code:

-- NEED MORE INDENTATION ---------------------------------------------- temp.elm

I was partway through parsing a record type, but I got stuck here:

1| type alias Stuff = {
2|     a : String,
3|     bananas : Int
4| }
I need this curly brace to be indented more. Try adding some spaces before it!

Note: If you are trying to define a record type across multiple lines, I
recommend using this format:

    { name : String
    , age : Int
    , height : Float

Notice that each line starts with some indentation. Usually two or four spaces.
This is the stylistic convention in the Elm ecosystem.

Thanks for reporting this case! The improved version should become available along with a bunch of other improvements once Elm 0.19.1 is released.

@evancz evancz closed this Jul 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.