Regression since 7.10.3, "variable not in scope" errors sometimes get buried under a sea of much less relevant errors.
Me and Neil Mitchell have ran into this quite a few times while using GHCid, here is our discussion:
https://github.com/ndmitchell/ghcid/issues/159
Here is a small reproducible example:
module Main where
foo :: String
foo = show a
where a = baz
bar :: Int
bar = 1
main = putStrLn foo
GHC 8.0.x and above will say
src/Main.hs:4:7: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘show’
prevents the constraint ‘(Show a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
...plus 23 others
...plus 212 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: show a
In an equation for ‘foo’:
foo
= show a
where
a = baz
|
4 | foo = show a
| ^^^^^^
src/Main.hs:5:13: error:
• Variable not in scope: baz
• Perhaps you meant ‘bar’ (line 8)
|
5 | where a = baz
| ^^^
It's much more useful and much less noisy what 7.10.3 reports:
src/Main.hs:5:13:
Not in scope: ‘baz’
Perhaps you meant ‘bar’ (line 8)
So a desired output would be something like this for a later GHC release:
src/Main.hs:5:13: error:
• Variable not in scope: baz
• Perhaps you meant ‘bar’ (line 8)
|
5 | where a = baz
| ^^^
Or if someone is adamant about keeping the other errors even when there are out of scope variables present, then at least can we please reorder them such that the much more relevant out-of-scope errors are at the top?
src/Main.hs:5:13: error:
• Variable not in scope: baz
• Perhaps you meant ‘bar’ (line 8)
|
5 | where a = baz
| ^^^
src/Main.hs:4:7: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘show’
prevents the constraint ‘(Show a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance (Show a, Show b) => Show (Either a b)
-- Defined in ‘Data.Either’
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
...plus 23 others
...plus 212 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: show a
In an equation for ‘foo’:
foo
= show a
where
a = baz
|
4 | foo = show a
| ^^^^^^
I might even be up for fixing this if there is agreement on the next steps to be taken. (Though I've never contributed to GHC before, on the surface this doesn't seem hard to fix.)
What do you think?
Trac metadata
Trac field | Value |
---|---|
Version | 8.4.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | ntdmitchel |
Operating system | |
Architecture |