GHC does not pull out TypeErrors aggressively enough
GHC does not consider a constraint such as `TypeError blah ~ Int` to be insoluble:
```hs
insolubleCt :: Ct -> Bool
insolubleCt (CIrredCan ir_ct) = insolubleIrredCt ir_ct
insolubleCt _ = False
insolubleIrredCt :: IrredCt -> Bool
insolubleIrredCt (IrredCt { ir_ev = ev, ir_reason = reason })
= isInsolubleReason reason
|| isTopLevelUserTypeError (ctEvPred ev)
isTopLevelUserTypeError pred =
isJust (userTypeError_maybe pred) || isJust (isUnsatisfiableCt_maybe pred)
userTypeError_maybe ty
| Just ty' <- coreView ty = userTypeError_maybe ty'
userTypeError_maybe (TyConApp tc (_kind : msg : _))
| tyConName tc == errorMessageTypeErrorFamName
= Just msg
userTypeError_maybe _
= Nothing
```
Really, we should be using `deepUserTypeError_maybe` which pulls out all nested occurences of `TypeError` except for those nested under type families (as the type family might reduce and the error could then go away).
One symptom of this is that we fail to recognise that the provided equation for `testFn` can never match in the following program:
```hs
data N = Z | S N
type SNat :: N -> UnliftedType
data SNat n where
SZ :: SNat Z
SS :: SNat n -> SNat (S n)
type (-) :: N -> N -> N
type family a - b where
n - Z = n
Z - S _ = TypeError ( Text "impossible" )
S n - S m = n - m
testFn :: SNat n -> SNat m -> SNat (n - m) -> Int
testFn SZ (SS _) (SS _) = 3
-- [G] g1 :: n ~ Z
-- [G] g2 :: m ~ S m1
-- [G] g3 :: (n-m) ~ S m2
-- Use the first two givens to substitute in the third, we get:
-- [G] g3' :: Z - S m1 ~ S m2
-- Reduce the LHS using the type family
-- [G] g3'' :: TypeError ... ~ S m2
-- Hence g3'' is insoluble and the equation can never match
```
issue