haskell / haskell/error-messages

Possibly confusing "inaccessible right hand side" with nested `Void`-like type

Open
#33 4 comments 0 reactions 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

(*based on a true story*)
```haskell
{-# LANGUAGE NamedFieldPuns #-}

module Test where

data A

data B = B
{ stuff :: !Int,
morestuff :: !Double,
a :: !A
}

data C = C
{ foo :: !Int,
bar :: !Bool,
baz :: !B
}
```
and consider the function
```haskell
fff :: C -> Int
fff c = if bar then foo else 0
where
C {foo, bar} = c
```
This results in a warning (since GHC 8.8, see 4th bullet point [here](https://downloads.haskell.org/ghc/8.8.4/docs/html/users_guide/8.8.1-notes.html#language))
```
Test.hs:22:5: warning: [-Woverlapping-patterns]
Pattern match has inaccessible right hand side
In a pattern binding: C {foo, bar} = ...
|
22 | C {foo, bar} = c
| ^^^^^^^^^^^^^^^^
```
Now imagine that `B` and `A` are defined in a completely different place (maybe `A` and the new field `a` in `B` were recently introduced as placeholders) than `fff`. Then this message gives no direct hints what went wrong, and the problematic nested field isn't even mentioned in `fff`.

(Also, it is a bit confusing that the **right** hand side is supposed to be inaccessible)

I find it very nice that GHC can warn about this, but maybe it could give a hint which field is `Void`-like in this case?

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.