haskell / haskell/haskell-language-server

Inconsistent/unhelpful types in hover messages

Open
#1,691 0 comments 2 reactions 0 assignees View on GitHub
component: ghcide type: bug
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
2d 19h
Merged PRs (30d)
11

Description

I'm in the middle of case bashing out some code. It looks like this:

```
type (⥤) :: (*, *) -> (*, *) -> *
data ax ⥤ by
where
Pairrow :: (a -> b) -> (x -> y) -> '(a, x) ⥤ '(b, y)

infixr 0 ⥤

type (:⚡) :: (*, *) -> (*, *) -> *
data ax :⚡ by
where
LL :: x -> b -> '(a, x) :⚡ '(b, y)
LM :: a -> b -> '(a, x) :⚡ '(b, y)
LR :: a -> y -> '(a, x) :⚡ '(b, y)

infixr 5 :⚡

type (⚡:) :: (*, *) -> (*, *) -> *
data ax ⚡: by
where
RL :: a -> y -> '(a, x) ⚡: '(b, y)
RM :: x -> y -> '(a, x) ⚡: '(b, y)
RR :: x -> b -> '(a, x) ⚡: '(b, y)

infixr 5 ⚡:

type (:⚡:) :: (*, *) -> (*, *) -> (*, *)
type ab :⚡: cd = '(ab :⚡ cd, ab ⚡: cd)

assoc :: forall a b c d e f. '(a, b) :⚡: ('(c, d) :⚡: '(e, f)) ⥤ ('(a, b) :⚡: '(c, d)) :⚡: '(e, f)
assoc = Pairrow
(\case
x `LL` (y `LL` z) -> (x `RM` y) `LL` z
-- x `LL` (y `LM` z) -> (x `RR` y) `LL` z
x `LL` (y `LM` z) -> (x `LL` y) `LM` z
x `LL` (y `LR` z) -> (x `LL` y) `LR` z

x `LM` (y `LL` z) -> (x `LR` y) `LM` z
x `LM` (y `LM` z) -> (x `LM` y) `LM` z
x `LM` (y `LR` z) -> (x `LM` y) `LR` z

x `LR` (y `RL` z) -> (x `LM` y) `LR` z
x `LR` (y `RM` z) -> (x `LR` y) `LR` z
-- x `LR` (y `RR` z) -> (x `LR` y) `LM` z
x `LR` (y `RR` z) -> (x `RL` y) `LL` z
)

(\case
l `RL` m -> _ l m
)
```

On the last line, there is a hole, plus a couple terms I pattern matched out. I would like to know the types of these terms to facilitate further programming. When I look at the hover information at various positions in that line, here is what I see:

On the pattern variable `l`:

![image](https://user-images.githubusercontent.com/3674056/113983866-f66f9e00-9839-11eb-8850-b0b85e0324c0.png)

On the infix pattern constructor `RL`:

![image](https://user-images.githubusercontent.com/3674056/113983895-01c2c980-983a-11eb-8a5a-ad8993b50335.png)

On the pattern variable `m`:

![image](https://user-images.githubusercontent.com/3674056/113983920-0ab39b00-983a-11eb-9f40-295c933ac467.png)

On the hole:

![image](https://user-images.githubusercontent.com/3674056/113983954-156e3000-983a-11eb-9a79-8f0bfabe0152.png)

On the use of `l` on the RHS of the arrow:

![image](https://user-images.githubusercontent.com/3674056/113983985-1d2dd480-983a-11eb-99a6-7976c29ca53f.png)

On the use of `m` on the RHS of the arrow:

![image](https://user-images.githubusercontent.com/3674056/113984010-2454e280-983a-11eb-8284-cb9d9c5db892.png)

So far, what this tells me is that:

```
l :: a
m :: y
```

Which is not very enlightening. The fact that the type of `l` is correct is a complete coincidence: the `a` it is talking about is not the same `a` as in the type signature. Moreover the type of `m` is apparently just "`y`", instead of the composite type involving `:⚡:` that I expect. The `a` and `y` type variables actually arise from the data constructor's type signature, and are both out of scope in this context.

If I change the type to:

```
assoc :: forall aa b c d e f. '(aa, b) :⚡: ('(c, d) :⚡: '(e, f)) ⥤ ('(aa, b) :⚡: '(c, d)) :⚡: '(e, f)
```

I would like to be informed that the type of `l` is `aa` (instead the hover information still blithely reports `l :: a`).

The eagle-eyed reader will notice that the hover information from the hole actually has _two_ type signatures in it. The second type signature is the more accurate one, so whatever machinery is producing the hole type error is unifying things sufficiently to tell me the complicated type of `m` (and similarly is talking about the "right" `a`, and would update to `aa` in the scenario above, etc.). It would be nice if the machinery that produced hover information was just as accurate.

I'm assuming the hover information is actually coming from the annotated AST in an .hie file or byproduct, so it might need some tweaking of `ghc` to accomplish this (maybe this needs to be filed there?).

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.