elm/compiler

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

Janiczek opened this issue · 3 comments

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.
  • Elm: 0.19.1
  • Browser: N/A
  • Operating System: macOS 12.6

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.

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.

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