compiler icon indicating copy to clipboard operation
compiler copied to clipboard

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

Open Janiczek opened this issue 3 years ago • 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

Janiczek avatar Oct 21 '22 16:10 Janiczek

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 Oct 21 '22 16:10 github-actions[bot]

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 avatar Nov 09 '22 21:11 turboMaCk

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

Janiczek avatar Nov 09 '22 23:11 Janiczek