... | ... | @@ -230,6 +230,79 @@ This is because under `NoPolyKinds`, GHC 9.2 will now always default any argumen |
|
|
```
|
|
|
2. Enable `PolyKinds` rather than `NoPolyKinds`, which prevents the `Type` defaulting from occurring.
|
|
|
|
|
|
### Improved Pattern-Match Coverage checker
|
|
|
|
|
|
GHC 9.2 has a more accurate pattern-match coverage checker, continuing work that was started in 9.0. As a consequence, GHC 9.2 may produce coverage-checking warnings that earlier versions did not. Some examples include:
|
|
|
|
|
|
* In some situations, `-Wincomplete-patterns` may warn about GADT pattern matches. For example:
|
|
|
|
|
|
```hs
|
|
|
{-# LANGUAGE GADTs #-}
|
|
|
{-# OPTIONS_GHC -Wincomplete-patterns #-}
|
|
|
module Foo where
|
|
|
|
|
|
data T1 a where
|
|
|
MkT1A :: T1 Int
|
|
|
MkT1B :: T1 Bool
|
|
|
MkT1C :: T1 Char
|
|
|
|
|
|
data T2 a where
|
|
|
MkT2A :: T2 Int
|
|
|
MkT2B :: T2 Bool
|
|
|
|
|
|
f :: T1 a -> T2 a -> ()
|
|
|
f t1 t2 =
|
|
|
case (t1, t2) of
|
|
|
(MkT1A, MkT2A) -> ()
|
|
|
(MkT1B, MkT2B) -> ()
|
|
|
```
|
|
|
|
|
|
This will not produce warnings in GHC 9.0, but this definition is not exhaustive:
|
|
|
|
|
|
```
|
|
|
λ> f MkT1C undefined
|
|
|
*** Exception: Foo.hs:(16,3)-(18,24): Non-exhaustive patterns in case
|
|
|
```
|
|
|
|
|
|
GHC 9.2, on the other hand, will warn about this:
|
|
|
|
|
|
```
|
|
|
Foo.hs:16:3: warning: [-Wincomplete-patterns]
|
|
|
Pattern match(es) are non-exhaustive
|
|
|
In a case alternative:
|
|
|
Patterns of type ‘(T1 a, T2 a)’ not matched: (MkT1C, _)
|
|
|
|
|
|
|
16 | case (t1, t2) of
|
|
|
| ^^^^^^^^^^^^^^^^...
|
|
|
```
|
|
|
|
|
|
There are two ways to fix the warning:
|
|
|
|
|
|
1. Add an "impossible" case for `MkT1C` that uses `EmptyCase` to match on the second argument:
|
|
|
|
|
|
```hs
|
|
|
{-# LANGUAGE EmptyCase #-}
|
|
|
|
|
|
f :: T1 a -> T2 a -> ()
|
|
|
f t1 t2 =
|
|
|
case (t1, t2) of
|
|
|
(MkT1A, MkT2A) -> ()
|
|
|
(MkT1B, MkT2B) -> ()
|
|
|
(MkT1C, _) -> case t2 of {}
|
|
|
```
|
|
|
|
|
|
2. Rearrange the order of arguments in the `case` expression:
|
|
|
|
|
|
```hs
|
|
|
f :: T1 a -> T2 a -> ()
|
|
|
f t1 t2 =
|
|
|
case (t2, t1) of
|
|
|
(MkT2A, MkT1A) -> ()
|
|
|
(MkT2B, MkT1B) -> ()
|
|
|
```
|
|
|
|
|
|
This works because pattern-match coverage-checking works left-to-right, so the `MkT1C` pattern is never reachable as long as one of `MkT2A` or `MkT2B` is matched before it on the left.
|
|
|
|
|
|
---
|
|
|
|
|
|
## Library changes
|
... | ... | |