diff options
-rw-r--r-- | compiler/coreSyn/CoreLint.hs | 13 | ||||
-rw-r--r-- | compiler/coreSyn/CoreUtils.hs | 5 |
2 files changed, 17 insertions, 1 deletions
diff --git a/compiler/coreSyn/CoreLint.hs b/compiler/coreSyn/CoreLint.hs index c454334d46..d5b031ace5 100644 --- a/compiler/coreSyn/CoreLint.hs +++ b/compiler/coreSyn/CoreLint.hs @@ -657,6 +657,7 @@ lintCoreExpr e@(Case scrut var alt_ty alts) = ; alt_ty <- lintInTy alt_ty ; var_ty <- lintInTy (idType var) + -- See Note [No alternatives lint check] ; when (null alts) $ do { checkL (not (exprIsHNF scrut)) (ptext (sLit "No alternatives for a case scrutinee in head-normal form:") <+> ppr scrut) @@ -715,6 +716,18 @@ kind coercions and produce the following substitution which is to be applied in the type variables: k_ag ~~> * -> * +Note [No alternatives lint check] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Case expressions with no alternatives are odd beasts, and worth looking at +in the linter. + +Certainly, it would be terribly wrong if the scrutinee was already in head +normal form. That is the first check. + +Furthermore, we should be able to see why GHC believes the scrutinee is +diverging for sure. That is the second check. see #10180. + ************************************************************************ * * \subsection[lintCoreArgs]{lintCoreArgs} diff --git a/compiler/coreSyn/CoreUtils.hs b/compiler/coreSyn/CoreUtils.hs index 46d4f58c5b..e0d94c4494 100644 --- a/compiler/coreSyn/CoreUtils.hs +++ b/compiler/coreSyn/CoreUtils.hs @@ -2108,7 +2108,10 @@ rhsIsStatic platform is_dynamic_name cvt_integer rhs = is_static False rhs ************************************************************************ -} --- | True if the type has no non-bottom elements +-- | True if the type has no non-bottom elements, e.g. when it is an empty +-- datatype, or a GADT with non-satisfiable type parameters, e.g. Int :~: Bool. +-- +-- See Note [No alternatives lint check] for one use of this function. isEmptyTy :: Type -> Bool isEmptyTy ty -- Data types with no constructors are empty |