New not-in-scope behaviour + deferred typed holes = disappearing error messages
The following code snippet is well-typed, and GHC is fine with it:
{-# LANGUAGE TypeFamilies #-}
import Control.Monad -- comment this out to cause error
import Data.IORef
class MonadRef m where
type Ref m :: * -> *
newRef :: a -> m (Ref m a)
readRef :: Ref m a -> m a
instance MonadRef IO where
type Ref IO = IORef
newRef = newIORef
readRef = readIORef
main :: IO ()
main = newRef (pure ()) >>= join . readRef
However, if one removes the import of Control.Monad
, then GHC treats join
as a typed hole due to #10569 (closed), but fails to infer its type, causing errors:
test.hs:17:8-23: error: …
• Couldn't match type ‘Ref m0’ with ‘IORef’
...
test.hs:17:29-32: error: …
Variable not in scope: join :: m0 (f0 ()) -> IO ()
By default the not-in-scope error is reported, but if -fdefer-typed-holes
is in effect, only the type error is reported and the scope error just vanishes, leaving the user (at least me) puzzled.
Not-in-scope errors should always be reported.