TypeError hides a second error message
Summary
Using TypeError seems to hide other type error messages due to eg, bad arguments passed to a function.
Steps to reproduce
Load into ghci:
{-# LANGUAGE DataKinds, UndecidableInstances, TypeFamilies #-}
import GHC.TypeLits
type family Check x :: Bool where
Check 'True = 'True
Check x = 'False
foo :: Check 'False ~ 'True => Int -> String
foo n = "never reached"
type family Check2 x :: Bool where
Check2 'True = 'True
Check2 x = TypeError ('Text "no")
foo2 :: Check2 'False ~ 'True => Int -> String
foo2 n = "never reached"
ghci> foo "bar"
<interactive>:69:1: error:
• Couldn't match type ‘'False’ with ‘'True’
arising from a use of ‘foo’
• In the expression: foo "bar"
In an equation for ‘it’: it = foo "bar"
<interactive>:69:5: error:
• Couldn't match expected type ‘Int’ with actual type ‘[Char]’
• In the first argument of ‘foo’, namely ‘"bar"’
In the expression: foo "bar"
In an equation for ‘it’: it = foo "bar"
ghci> foo2 "bar"
<interactive>:70:1: error:
• no
• In the expression: foo2 "bar"
In an equation for ‘it’: it = foo2 "bar"
Expected behavior
I expected to see the same error about Int vs [Char] for foo2 as is shown for foo, as well as the custom TypeError. However, the use of TypeError somehow prevents the Int vs [Char] error from being displayed.
This is preventing me from using TypeError in situations where there might be another, more basic type error in the same code.
This may be related to #14771
Environment
- GHC version used: 8.4.4, 8.6.5
Edited by Joey Hess