diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2020-11-18 10:29:25 +0100 |
---|---|---|
committer | Sebastian Graf <sebastian.graf@kit.edu> | 2020-11-18 13:53:43 +0100 |
commit | 9667ab7d2fe7f115902003638a2a9e9a61576fb8 (patch) | |
tree | c6cc6b7c0ff87f41468f16d51727f4009d035d6c /compiler/GHC | |
parent | fc644b1a643128041cfec25db84e417851e28bab (diff) | |
download | haskell-wip/T18932.tar.gz |
PmCheck: Print types of uncovered patterns (#18932)wip/T18932
In order to avoid confusion as in #18932, we display the type of the
match variables in the non-exhaustiveness warning, e.g.
```
T18932.hs:14:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘g’:
Patterns of type ‘T a’, ‘T a’, ‘T a’ not matched:
(MkT2 _) (MkT1 _) (MkT1 _)
(MkT2 _) (MkT1 _) (MkT2 _)
(MkT2 _) (MkT2 _) (MkT1 _)
(MkT2 _) (MkT2 _) (MkT2 _)
...
|
14 | g (MkT1 x) (MkT1 _) (MkT1 _) = x
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
It also allows us to omit the type signature on wildcard matches which
we previously showed in only some situations, particularly
`-XEmptyCase`.
Fixes #18932.
Diffstat (limited to 'compiler/GHC')
-rw-r--r-- | compiler/GHC/HsToCore/Pmc.hs | 5 | ||||
-rw-r--r-- | compiler/GHC/HsToCore/Pmc/Ppr.hs | 17 |
2 files changed, 6 insertions, 16 deletions
diff --git a/compiler/GHC/HsToCore/Pmc.hs b/compiler/GHC/HsToCore/Pmc.hs index 7af0d4605e..651f37f909 100644 --- a/compiler/GHC/HsToCore/Pmc.hs +++ b/compiler/GHC/HsToCore/Pmc.hs @@ -381,7 +381,10 @@ reportWarnings dflags ctx@(DsMatchContext kind loc) vars case vars of -- See #11245 [] -> text "Guards do not cover entire pattern space" _ -> let us = map (\nabla -> pprUncovered nabla vars) nablas - in hang (text "Patterns not matched:") 4 + pp_tys = pprQuotedList $ map idType vars + in hang + (text "Patterns of type" <+> pp_tys <+> text "not matched:") + 4 (vcat (take maxPatterns us) $$ dots maxPatterns us) approx_msg = vcat diff --git a/compiler/GHC/HsToCore/Pmc/Ppr.hs b/compiler/GHC/HsToCore/Pmc/Ppr.hs index fea1ecfe39..3de6a14970 100644 --- a/compiler/GHC/HsToCore/Pmc/Ppr.hs +++ b/compiler/GHC/HsToCore/Pmc/Ppr.hs @@ -136,26 +136,13 @@ checkRefuts x = do -- | Pretty print a variable, but remember to prettify the names of the variables -- that refer to neg-literals. The ones that cannot be shown are printed as --- underscores. Even with a type signature, if it's not too noisy. +-- underscores. pprPmVar :: PprPrec -> Id -> PmPprM SDoc --- Type signature is "too noisy" by my definition if it needs to parenthesize. --- I like "not matched: _ :: Proxy (DIdEnv (Id, SDoc))", --- but I don't like "not matched: (_ :: stuff) (_:_) (_ :: Proxy (DIdEnv (Id, SDoc)))" --- The useful information in the latter case is the constructor that we missed, --- not the types of the wildcards in the places that aren't matched as a result. pprPmVar prec x = do nabla <- ask case lookupSolution nabla x of Just (PACA alt _tvs args) -> pprPmAltCon prec alt args - Nothing -> fromMaybe typed_wildcard <$> checkRefuts x - where - -- if we have no info about the parameter and would just print a - -- wildcard, also show its type. - typed_wildcard - | prec <= sigPrec - = underscore <+> text "::" <+> ppr (idType x) - | otherwise - = underscore + Nothing -> fromMaybe underscore <$> checkRefuts x pprPmAltCon :: PprPrec -> PmAltCon -> [Id] -> PmPprM SDoc pprPmAltCon _prec (PmAltLit l) _ = pure (ppr l) |