Report an error when applying a type family associated with a class to a type that's not an instance of the class
Summary
I wasted at least an hour on this issue, which I originally reported at https://github.com/well-typed/generics-sop/issues/152 . I'm reporting it here as suggested because I can't be the only GHC user dumb enough to be confused by the behaviour.
Trying to apply a class method to a value whose type is an instance of the type class results in an understandable error message
No instance for YourType arising from a use of theMethod
Trying to apply an associated type family to a type that's not an instance of the type class, in contrast, does not result in any error message by itself: the application will simply remain stuck.
Steps to reproduce
GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /tmp/haskell-stack-ghci/2a3bbd58/ghci-script
Prelude> :module + Generics.SOP Generics.SOP.GGP
Prelude Generics.SOP Generics.SOP.GGP> :set -XDeriveGeneric
Prelude Generics.SOP Generics.SOP.GGP> newtype N = N Int deriving GHC.Generics.Generic
Prelude Generics.SOP Generics.SOP.GGP> :k! Code N
Code N :: [[*]]
= Code N
Prelude Generics.SOP Generics.SOP.GGP> :k! GCode N
GCode N :: [[*]]
= '[ '[Int]]
Expected behavior
A clear error message like
No instance for (Generic N) arising from a use of ‘Code’
Environment
- GHC version used: 8.10.7 and 9.2.1