summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc/Gen/Default.hs
diff options
context:
space:
mode:
authorKrzysztof Gogolewski <krzysztof.gogolewski@tweag.io>2021-01-08 11:57:32 +0100
committerKrzysztof Gogolewski <krzysztof.gogolewski@tweag.io>2021-01-08 12:16:20 +0100
commitc1e24faa9579dd4b50a46c65ebe3f3a292139422 (patch)
tree94890ed5c935804f22a0fcc2938321a627943dcd /compiler/GHC/Tc/Gen/Default.hs
parentbd877edd9499a351db947cd51ed583872b2facdf (diff)
downloadhaskell-wip/better-default.tar.gz
Improve defaulting detection codewip/better-default
As suggested at https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4701#note_322397 This makes sure that the code does not create an ill-kinded type.
Diffstat (limited to 'compiler/GHC/Tc/Gen/Default.hs')
-rw-r--r--compiler/GHC/Tc/Gen/Default.hs9
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/GHC/Tc/Gen/Default.hs b/compiler/GHC/Tc/Gen/Default.hs
index d37f26df40..0a50f3e983 100644
--- a/compiler/GHC/Tc/Gen/Default.hs
+++ b/compiler/GHC/Tc/Gen/Default.hs
@@ -12,6 +12,7 @@ import GHC.Prelude
import GHC.Hs
import GHC.Core.Class
+import GHC.Core.Type (typeKind)
import GHC.Tc.Utils.Monad
import GHC.Tc.Utils.Env
import GHC.Tc.Gen.HsType
@@ -85,10 +86,10 @@ check_instance :: Type -> Class -> TcM Bool
-- Check that ty is an instance of cls
-- We only care about whether it worked or not; return a boolean
check_instance ty cls
- = do { (_, success) <- discardErrs $
- askNoErrs $
- simplifyDefault [mkClassPred cls [ty]]
- ; return success }
+ | eqType (typeKind $ mkTyConTy $ classTyCon cls)
+ (mkVisFunTyMany (typeKind ty) constraintKind)
+ = simplifyDefault [mkClassPred cls [ty]]
+ | otherwise = return False
defaultDeclCtxt :: SDoc
defaultDeclCtxt = text "When checking the types in a default declaration"