[GHC] #12792: Wrong error message when using a data type as a class instance head
GHC
ghc-devs at haskell.org
Wed Nov 30 22:00:56 UTC 2016
#12792: Wrong error message when using a data type as a class instance head
-------------------------------------+-------------------------------------
Reporter: nomeata | Owner:
Type: bug | Status: new
Priority: low | Milestone:
Component: Compiler | Version: 8.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
error/warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by nomeata):
* priority: normal => low
Comment:
Related, but still minor: GHC would happily suggest a data type
constructor where a class name is expected.
{{{#!hs
Prelude> data Bar a
Prelude> instance Baz a
<interactive>:3:10:
Not in scope: type constructor or class ‘Baz’
Perhaps you meant ‘Bar’ (line 2)
}}}
I read more through the code and see now why this is not easily done. The
renamer does not know which names have methods, but for methods it knows
what name they belong to (their parent, also just a name), so this can be
caught early in the renamer.
But since this parent information is “untyped”, we can actually trick the
compiler in passing through the renamer, by using a record label (whose
parent is the data type) as a class name:
{{{#!hs
data List a = List { bar :: a}
instance List Int where bar = bar
}}}
produces
{{{
[1 of 1] Compiling Main (.hs -> .o)
/tmp/T12792.hs:2:10: error:
• Expected a constraint, but ‘List Int’ has kind ‘*’
• In the instance declaration for ‘List Int’
}}}
I get one way of getting saner behavior and early error reporting here
would be to change the `NameSpace` type to distinguish between TyCons and
classes, and at every use of namespaces pay close attention where one, the
other, or both are valid. Since a `Name` knows it `NameSpace`, this would
fix the problem at hand. But it would be quite a bit of work, and without
other obvious benefits, not worth it.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12792#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list