Confusing Core Lint error
Summary
When working on #17478 (adding a Core pass to maximise shadowing, to sanity-check ghc), I ran across a rather confusingly-worded lint error message. I had a broken pass, which (more-or-less) renamed all uniques to coincide, and ran that pass and Lint over the program
app :: (a -> b) -> a -> b
app g xs = g xs
This generated the following error - notice how lint tells us the Var: xs
, but what it is really complaining about is the occurrence of g
, which is bound by xs
, since they have the same unique (rB7
here).
This is rather confusing, since, looking at the name, there is nothing wrong with how xs
is bound and used!
*** Core Lint errors : in result of Core plugin: Shadowing ***
<no location info>: warning:
[RHS of app{v rB7}[lidx] :: forall @a{tv aDK}[tv] @b{tv aDL}[tv].
(a{tv aDK}[tv] -> b{tv aDL}[tv])
-> a{tv aDK}[tv] -> b{tv aDL}[tv]]
[in body of lambda with binder a{tv rB7}[tv] :: TYPE{(w) tc 32Q}
'LiftedRep{(w) d 63A}]
[in body of lambda with binder b{tv rB7}[tv] :: TYPE{(w) tc 32Q}
'LiftedRep{(w) d 63A}]
[in body of lambda with binder g{v rB7}[lid] :: a{tv rB7}[tv]
-> b{tv rB7}[tv]]
[in body of lambda with binder xs{v rB7}[lid] :: a{tv rB7}[tv]]
In the expression: g{v rB7}[lid] xs{v rB7}[lid]
In the expression: g{v rB7}[lid] xs{v rB7}[lid]
Substitution: [TCvSubst
In scope: InScope {a{tv XBa} b{tv XBb} $trModule{v raK} xs{v rB7}}
Type env: [rB7 :-> b{tv XBb}[tv]]
Co env: []]
Mismatch in type between binder and occurrence
Var: xs{v rB7}[lid]
Binder type: b{tv XBb}[tv]
Occurrence type: b{tv XBb}[tv] -> b{tv XBb}[tv]
Before subst: a{tv rB7}[tv] -> b{tv rB7}[tv]
*** Offending Program ***
app{v rB7}[lidx]
app{v rB7}[lidx]
= \ @ a{tv rB7}[tv] @ b{tv rB7}[tv] g{v rB7}[lid] xs{v rB7}[lid] ->
g{v rB7}[lid] xs{v rB7}[lid]
I have a fork of 8.6.5 https://gitlab.haskell.org/brprice/ghc/tree/WIP/better-lint-var-type-msg which changes the error message to explicitly print both the problematic binder and occurrence, which I think makes the error much more obvious:
*** Core Lint errors : in result of Core plugin: Shadowing ***
<no location info>: warning:
[RHS of app{v rdF}[lidx] :: forall @a{tv afq}[tv] @b{tv afr}[tv].
(a{tv afq}[tv] -> b{tv afr}[tv])
-> a{tv afq}[tv] -> b{tv afr}[tv]]
[in body of lambda with binder a{tv rdF}[tv] :: TYPE{(w) tc 32Q}
'LiftedRep{(w) d 63A}]
[in body of lambda with binder b{tv rdF}[tv] :: TYPE{(w) tc 32Q}
'LiftedRep{(w) d 63A}]
[in body of lambda with binder g{v rdF}[lid] :: a{tv rdF}[tv]
-> b{tv rdF}[tv]]
[in body of lambda with binder xs{v rdF}[lid] :: a{tv rdF}[tv]]
In the expression: g{v rdF}[lid] xs{v rdF}[lid]
In the expression: g{v rdF}[lid] xs{v rdF}[lid]
Substitution: [TCvSubst
In scope: InScope {a{tv XdI} b{tv XdJ} $trModule{v r7D} xs{v rdF}}
Type env: [rdF :-> b{tv XdJ}[tv]]
Co env: []]
Mismatch in type between binder and occurrence
Binder: xs{v rdF}[lid]
Occurrence: g{v rdF}[lid]
Binder type: b{tv XdJ}[tv]
Occurrence type: b{tv XdJ}[tv] -> b{tv XdJ}[tv]
Before subst: a{tv rdF}[tv] -> b{tv rdF}[tv]
*** Offending Program ***
app{v rdF}[lidx]
app{v rdF}[lidx]
= \ @ a{tv rdF}[tv] @ b{tv rdF}[tv] g{v rdF}[lid] xs{v rdF}[lid] ->
g{v rdF}[lid] xs{v rdF}[lid]
I'm happy to make a merge request if this change is wanted (modulo bikeshedding) - though it is such a trivial change that it may be easier to not round trip via me!
Steps to reproduce
I don't know of a decent way to reproduce without a broken plugin. See comment #17803 (comment 256576).
Environment
- GHC version used: 8.6.5