[GHC] #12792: Wrong error message when using a data type as a class instance head

#12792: Wrong error message when using a data type as a class instance head -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Keywords: newcomer | 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: -------------------------------------+------------------------------------- {{{ Prelude> data List a = Nil | Cons a (List a) Prelude> instance List a <interactive>:3:10: error: • Expected a constraint, but ‘List a’ has kind ‘*’ • In the instance declaration for ‘List a’ Prelude> instance List a where foo = foo <interactive>:2:23: error: ‘foo’ is not a (visible) method of class ‘List’ }}} Clearly, the constraint check should happen before we look at the method names. Happens with 7.10 and 8.0.1 and HEAD. Shouldn’t be hard, marking at newcomer. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12792 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12792: Wrong error message when using a data type as a class instance head -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | 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 simonpj): * keywords: newcomer => Comment: I sort of agree but it's architecturally difficult. * The "not a visible method" message comes from the renamer * The kind error comes from the type checker It's not clear to me how to make the latter suppress the former. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12792#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12792: Wrong error message when using a data type as a class instance head -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | 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: | -------------------------------------+------------------------------------- Comment (by nomeata): Do we need full kind-checking? The renamer already knows the concrete TyCon that is heading the instance. Shouldn’t `isClassTyCon` be sufficient here? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12792#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12792: Wrong error message when using a data type as a class instance head -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | 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: | -------------------------------------+------------------------------------- Comment (by simonpj): We don't have `TyCon`s in the renamer; only `Name`s. (Unless imported, or from an earlier GHCi line. So yes, for imported things one could do better. Maybe that is useful enough to do.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12792#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Unless imported, or from an earlier GHCi line. So yes, for imported
#12792: Wrong error message when using a data type as a class instance head -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | 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: | -------------------------------------+------------------------------------- Comment (by nomeata): things one could do better. Maybe that is useful enough to do. I think it would. (I’m still not convined that it’s not possible otherwise. If the renamer knows about what “Names” have which “methods” (and it seems it does, given the error message), then surely it must know what “Names” can have “methods” in the first place – namely classes. But I should just try it myself, or at least read the code carefully, instead of rambling here.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12792#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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
participants (1)
-
GHC