Commit efc0372a authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Not-in-scope variables are always errors

This fixes Trac #12406.  A not-in-scope error shoudl be an error
even if you have -fdefer-typed-holes.
parent 34da8e51
......@@ -621,9 +621,15 @@ maybeReportHoleError ctxt ct err
HoleWarn -> reportWarning (Reason Opt_WarnPartialTypeSignatures) err
HoleDefer -> return ()
-- Otherwise this is a typed hole in an expression
| isOutOfScopeCt ct
= -- Always report an error for out-of-scope variables
-- See Trac #12170, #12406
reportError err
-- Otherwise this is a typed hole in an expression,
-- but not for an out-of-scope variable
| otherwise
= -- If deferring, report a warning only if -Wtyped-holds is on
= -- If deferring, report a warning only if -Wtyped-holes is on
case cec_expr_holes ctxt of
HoleError -> reportError err
HoleWarn -> reportWarning (Reason Opt_WarnTypedHoles) err
......
T12156.hs:3:14: warning: [-Wtyped-holes (in -Wdefault)]
Variable not in scope: v
T12156.hs:3:14: error: Variable not in scope: v
......@@ -64,4 +64,4 @@ test('SuperCls', normal, compile, [''])
test('T12033', normal, compile, [''])
test('T11339a', normal, compile, [''])
test('T11670', normal, compile, [''])
test('T12156', normal, compile, ['-fdefer-typed-holes'])
test('T12156', normal, compile_fail, ['-fdefer-typed-holes'])
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fdefer-typed-holes #-}
module T12406 where
-- 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
foo :: IO ()
foo = newRef (pure ()) >>= join . readRef
T12406.hs:20:7: error:
• Couldn't match type ‘Ref m0’ with ‘IORef’
Expected type: IO (Ref m0 (f0 ()))
Actual type: IO (Ref IO (f0 ()))
The type variable ‘m0’ is ambiguous
• In the first argument of ‘(>>=)’, namely ‘newRef (pure ())’
In the expression: newRef (pure ()) >>= join . readRef
In an equation for ‘foo’: foo = newRef (pure ()) >>= join . readRef
T12406.hs:20:28: error:
Variable not in scope: join :: m0 (f0 ()) -> IO ()
......@@ -423,4 +423,5 @@ test('T12063', [ expect_broken(12063), extra_clean(['T12063.hi-boot', 'T12063.o-
test('T11974b', normal, compile_fail, [''])
test('T12151', normal, compile_fail, [''])
test('T7437', normal, compile_fail, [''])
test('T12177', normal, compile_fail, [''])
\ No newline at end of file
test('T12177', normal, compile_fail, [''])
test('T12406', normal, compile_fail, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment