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

Pattern parser not hinting at missing comma #2328

Open Golden-Phy opened 1 month ago

Golden-Phy commented 1 month ago

Quick Summary: When destructuring a tuple a missing comma will lead the parser to correctly complain at the next token, but the message fails to communicate that a comma (,) is also a valid continuation of the pattern.

SSCCE

module Main exposing (..)

import Browser
import Html exposing (Html, div, text)

-- MAIN
main =
  Browser.sandbox { init = init, update = update, view = view }

-- UPDATE
update : () -> Model -> Model
update _ model =
  model

-- MODEL
type alias Model = Int

init : Model
init = 3

-- VIEW
view : Model -> Html ()
view model =
    div [] [text (String.fromInt(factorial (model, 0)))]

factorial : (Int, Int) -> Int
factorial (i _) =
  if i <= 1 then 1 else i * (factorial (i - 1 , 1))

Additional Details

Compiler output:

UNFINISHED PARENTHESES
Jump to problem
I was partway through parsing a pattern, but I got stuck here:

27| factorial (i _) =

                 ^
I was expecting a closing parenthesis next, so try adding a ) to see if that
helps?
github-actions[bot] commented 1 month ago

Thanks for reporting this! To set expectations:

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