haskell / haskell/error-messages

Not a data constructor clarity

Open
#49 1 comment 1 reaction 0 assignees View on GitHub
status:Composing error message tool:GHC type:error-message
Dominant language
No language data
Stars
76
Forks
19
PR merge metrics
No merged PRs in 30d

Description

For a module containing only:
```hs
data Foo = bar
```
we get the error message:
```
error: Not a data constructor: ‘bar’
|
1 | data Foo = bar
|
```
when compiling or loading into ghci. It came up that this message does not explain why 'bar' is not a valid data constructor, that it does not start with a capital letter or ':'. It would be useful to have that information presented alongside this error message, perhaps with something like:
```
error: Not a data constructor: ‘bar’
Note: data constructors must begin with a capital letter or ':'
|
1 | data Foo = bar
|
```
or an equivalent that better matches the style of GHC's other error messages. If adding an additional note would not fit that style, simply changing the message to:
```
error: Not a valid data constructor: ‘bar’
|
1 | data Foo = bar
|
```
would help make it more clear that 'bar' _cannot_ be a data constructor and that this is a syntactical issue. I believe there are no other methods of raising this error, but I could see either approach making such cases more confusing if they do exist.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the diagnostic by compiling or loading the shown `data Foo = bar` snippet into GHCi, then trace where the “Not a data constructor” message is produced. Done means the diagnostic clearly explains the capitalization or `:` requirement, with the behavior covered by the relevant compiler error test if one is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Feature
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.