gren-lang / gren-lang/compiler

Unclear error for two doc comments for a declaration

Open
#366 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

error message
Dominant language
Haskell
Stars
503
Forks
29
PR merge metrics
No merged PRs in 30d

Description

Reported by @gilramir on Discord.

The new parser's error message for multiple doc-comments on a function could be clearer. I didn't know until right now that there could only be one doc comment on a function (even with the existing compiler), but I see why it should be so.

From the new parser:

--Could not parse this file-------------------------------- src/ViewItems.gren

21|
22| {-| This is doc comment #1 -}
23| {-| This is doc comment #2 -}
    ^
24| viewItems : Array String -> String
25| viewItems items =

Expected keyword 'port'
Expected keyword 'type'
Invalid character in variable name

whereas in the current parser:

-- UNEXPECTED SYMBOL ---------------------------------------- src/ViewItems.gren

I am getting stuck because this line starts with the { symbol:

23| {-| This is doc comment #2 -}
    ^
When a line has no spaces at the beginning, I expect it to be a declaration like
one of these:

    greet : String -> String
    greet name =
      "Hello " ++ name ++ "!"

    type User = Anonymous | LoggedIn String

If this is not supposed to be a declaration, try adding some spaces before it?

Both versions are unclear, actually 🙂

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example from src/ViewItems.gren with the new parser and compare it with the current parser's diagnostics. Read the parser entry points responsible for doc comments and declaration errors; done means multiple doc comments produce a clear, specific diagnostic explaining the one-comment rule.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.