summaryrefslogtreecommitdiff
path: root/compiler/deSugar/Check.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2017-08-05 12:02:54 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2017-08-05 12:02:55 -0400
commita267580e4ab37115dcc33f3b8a9af67b9364da12 (patch)
tree8cbea155ec76df9f91d44d03faa55e606f85b9cf /compiler/deSugar/Check.hs
parenta81b5b0067b6530f5883aeb0154a407a54d14c62 (diff)
downloadhaskell-a267580e4ab37115dcc33f3b8a9af67b9364da12.tar.gz
Don't warn when empty casing on Type
Summary: `Type` (a.k.a. `TYPE LiftedRep`) can be used at the type level thanks to `TypeInType`. However, expressions like ```lang=haskell f :: Type -> Int f x = case x of {} ``` were falsely claiming that the empty case on the value of type `Type` was non-exhaustive. The reason is a bit silly: `TYPE` is technically not an empty datatype in GHC's eyes, since it's a builtin, primitive type. To convince the pattern coverage checker otherwise, this adds a special case for `TYPE`. Test Plan: make test TEST=T14086 Reviewers: gkaracha, austin, bgamari, goldfire Reviewed By: goldfire Subscribers: goldfire, rwbarton, thomie GHC Trac Issues: #14086 Differential Revision: https://phabricator.haskell.org/D3819
Diffstat (limited to 'compiler/deSugar/Check.hs')
-rw-r--r--compiler/deSugar/Check.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/deSugar/Check.hs b/compiler/deSugar/Check.hs
index 2b1995cdd5..b0155d3e2f 100644
--- a/compiler/deSugar/Check.hs
+++ b/compiler/deSugar/Check.hs
@@ -27,6 +27,7 @@ import Id
import ConLike
import Name
import FamInstEnv
+import TysPrim (tYPETyCon)
import TysWiredIn
import TyCon
import SrcLoc
@@ -440,6 +441,19 @@ inhabitationCandidates fam_insts ty
(_:_) -> do var <- liftD $ mkPmId (toTcType core_ty)
let va = build_tm (PmVar var) dcs
return $ Right [(va, mkIdEq var, emptyBag)]
+
+ -- TYPE (which is the underlying kind behind Type, among others)
+ -- is conceptually an empty datatype, so one would expect this code
+ -- (from #14086) to compile without warnings:
+ --
+ -- f :: Type -> Int
+ -- f x = case x of {}
+ --
+ -- However, since TYPE is a primitive builtin type, not an actual
+ -- datatype, we must convince the coverage checker of this fact by
+ -- adding a special case here.
+ | tc == tYPETyCon -> pure (Right [])
+
| isClosedAlgType core_ty -> liftD $ do
var <- mkPmId (toTcType core_ty) -- it would be wrong to unify x
alts <- mapM (mkOneConFull var . RealDataCon) (tyConDataCons tc)