haskell / haskell/error-messages

Add suggestions in "not a (visible) method"

Open
#526 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
76
Forks
19
PR merge metrics
No merged PRs in 30d

Description

If I refer to an unknown method in a class

```hs
module M where

import Data.Data (Data (gunfold))

data T

instance Data T where
toConstr = undefined
gunfolt = undefined
```

I get this error:

```
M.hs:8:3: error:
‘toConstr’ is not a (visible) method of class ‘Data’
|
8 | toConstr = undefined
| ^^^^^^^^

M.hs:9:3: error:
‘gunfolt’ is not a (visible) method of class ‘Data’
|
9 | gunfolt = undefined
| ^^^^^^^
```

Contrast with:

```hs
module M2 where

import Data.Data (Data (gunfold))

a = toConstr
b = gunfolt
```

where I get helpful suggestions:

```
M2.hs:5:5: error:
• Variable not in scope: toConstr
• Perhaps you want to add ‘toConstr’ to the import list
in the import of ‘Data.Data’ (M2.hs:3:1-33).
|
5 | a = toConstr
| ^^^^^^^^

M2.hs:6:5: error:
• Variable not in scope: gunfolt
• Perhaps you meant ‘gunfold’ (imported from Data.Data)
|
6 | b = gunfolt
| ^^^^^^^
```

A cheap fix would be just to list all visible methods of the class in the error, classes usually don't have that many members.

Related: #13, about associated types.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.