elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 658 forks source link

Long list formatted all on one line causes a parser error (trailing comma) #2281

Open Janiczek opened 1 year ago

Janiczek commented 1 year ago

Quick Summary: Formatting long (in my case 64k long) lists all on one line causes a parser error, while formatting them "one element per line" compiles fine.

SSCCE

module Main exposing (main)

import Html

main =
    Html.text "compiles?"

list = [ 1, 1, 1, 1, 1, 1, 1, ... ] -- `1` repeated 64*1024 times

This results in

Detected problems in 1 module.
-- UNFINISHED LIST ------------------------------------------------ src/Main.elm

I was expecting to see another list entry after this comma:

-- snip for obvious reasons

Trailing commas are not allowed in lists, so the fix may be to delete the comma?

Note: I recommend using the following format for lists that span multiple lines:

    [ "Alice"
    , "Bob"
    , "Chuck"
    ]

Notice that each line starts with some indentation. Usually two or four spaces.
This is the stylistic convention in the Elm ecosystem.
github-actions[bot] commented 1 year ago

Thanks for reporting this! To set expectations:

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

turboMaCk commented 1 year ago

I wonder does the multi-line version that passes type check work in the end? I remember that because of what list literals compile to they can actually stack overflow for very long lists. At least I think that was a case in some version of compiler.

Janiczek commented 1 year ago

@turboMaCk It runs fine. Perhaps the list was not long enough or the issue was fixed :)