Commit c2b7a3d9 authored by Simon Peyton Jones's avatar Simon Peyton Jones

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.
parent 24d3276d
...@@ -966,7 +966,10 @@ notFound name ...@@ -966,7 +966,10 @@ notFound name
= do { lcl_env <- getLclEnv = do { lcl_env <- getLclEnv
; let stage = tcl_th_ctxt lcl_env ; let stage = tcl_th_ctxt lcl_env
; case stage of -- See Note [Out of scope might be a staging error] ; 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 $ _ -> failWithTc $
vcat[text "GHC internal error:" <+> quotes (ppr name) <+> vcat[text "GHC internal error:" <+> quotes (ppr name) <+>
text "is not in scope during type checking, but it passed the renamer", text "is not in scope during type checking, but it passed the renamer",
...@@ -986,13 +989,14 @@ wrongThingErr expected thing name ...@@ -986,13 +989,14 @@ wrongThingErr expected thing name
= failWithTc (pprTcTyThingCategory thing <+> quotes (ppr name) <+> = failWithTc (pprTcTyThingCategory thing <+> quotes (ppr name) <+>
text "used as a" <+> text expected) text "used as a" <+> text expected)
{- {- Note [Out of scope might be a staging error]
Note [Out of scope might be a staging error] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider Consider
x = 3 x = 3
data T = MkT $(foo x) 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'. 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 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 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)
...@@ -403,3 +403,4 @@ test('T11463', normal, compile_and_run, ['-v0 -dsuppress-uniques']) ...@@ -403,3 +403,4 @@ test('T11463', normal, compile_and_run, ['-v0 -dsuppress-uniques'])
test('T11680', normal, compile_fail, ['-v0']) test('T11680', normal, compile_fail, ['-v0'])
test('T11809', normal, compile, ['-v0']) test('T11809', normal, compile, ['-v0'])
test('T11797', normal, compile, ['-v0 -dsuppress-uniques']) 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