Commit 8405c2ed authored by Simon Peyton Jones's avatar Simon Peyton Jones Committed by Ben Gamari

Avoid double error on out-of-scope identifier

Trac #11941 demonstrated a case where an out-of-scope error also
gave rise to a (bogus and confusing) stage restriction message.

It's caused by the fact that out-of-scope errors do not stop
renaming, but rather return an "unbound name".  We need to
detect this in the stage-restriction test to avoid the double
error.  Easy fix.

(cherry picked from commit c2b7a3d9)
parent 2c5a5fc1
......@@ -955,7 +955,10 @@ notFound name
= do { lcl_env <- getLclEnv
; let stage = tcl_th_ctxt lcl_env
; case stage of -- See Note [Out of scope might be a staging error]
Splice {} -> stageRestrictionError (quotes (ppr name))
Splice {}
| isUnboundName name -> failM -- If the name really isn't in scope
-- don't report it again (Trac #11941)
| otherwise -> stageRestrictionError (quotes (ppr name))
_ -> failWithTc $
vcat[text "GHC internal error:" <+> quotes (ppr name) <+>
text "is not in scope during type checking, but it passed the renamer",
......@@ -975,13 +978,14 @@ wrongThingErr expected thing name
= failWithTc (pprTcTyThingCategory thing <+> quotes (ppr name) <+>
text "used as a" <+> text expected)
Note [Out of scope might be a staging error]
{- Note [Out of scope might be a staging error]
x = 3
data T = MkT $(foo x)
where 'foo' is is imported from somewhere.
This is really a staging error, because we can't run code involving 'x'.
But in fact the type checker processes types first, so 'x' won't even be
in the type envt when we look for it in $(foo x). So inside splices we
{-# LANGUAGE TemplateHaskell #-}
module T11941 where
import Data.Monoid
const (return []) $ mempty { getFrst = Just () }
T11941.hs:7:30: error:
Not in scope: ‘getFrst’
Perhaps you meant one of these:
‘getFirst’ (imported from Data.Monoid),
‘getLast’ (imported from Data.Monoid)
......@@ -407,3 +407,4 @@ test('T11463', normal, compile_and_run, ['-v0 -dsuppress-uniques'])
test('T11680', normal, compile_fail, ['-v0'])
test('T11809', normal, compile, ['-v0'])
test('T11797', normal, compile, ['-v0 -dsuppress-uniques'])
test('T11941', normal, compile_fail, ['-v0'])
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