From fd78f236219211985e82da77fea4f14be3ec3d72 Mon Sep 17 00:00:00 2001 From: simonpj Date: Thu, 9 Jan 2003 15:35:31 +0000 Subject: [PATCH] [project @ 2003-01-09 15:35:31 by simonpj] Catch a staging error that slipped through before --- ghc/compiler/typecheck/TcEnv.lhs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ghc/compiler/typecheck/TcEnv.lhs b/ghc/compiler/typecheck/TcEnv.lhs index ec765dc..23eba50 100644 --- a/ghc/compiler/typecheck/TcEnv.lhs +++ b/ghc/compiler/typecheck/TcEnv.lhs @@ -59,7 +59,7 @@ import TcType ( Type, ThetaType, TcKind, TcTyVar, TcTyVarSet, ) import qualified Type ( getTyVar_maybe ) import Rules ( extendRuleBase ) -import Id ( idName, isDataConWrapId_maybe ) +import Id ( idName, isLocalId, isDataConWrapId_maybe ) import Var ( TyVar, Id, idType ) import VarSet import VarEnv @@ -339,9 +339,22 @@ tcLookupIdLvl name = tcLookup name `thenM` \ thing -> case thing of ATcId tc_id lvl -> returnM (tc_id, lvl) - AGlobal (AnId id) -> returnM (id, impLevel) + AGlobal (AnId id) -- See [Note: Levels] + | isLocalId id -> returnM (id, topLevel) + | otherwise -> returnM (id, impLevel) other -> pprPanic "tcLookupIdLvl" (ppr name) +-- [Note: Levels] +-- Globals may either be imported, or may be from an earlier "chunk" +-- (separated by declaration splices) of this module. The former +-- *can* be used inside a top-level splice, but the latter cannot. +-- Hence we give the former impLevel, but the latter topLevel +-- E.g. this is bad: +-- x = [| foo |] +-- $( f x ) +-- By the time we are prcessing the $(f x), the binding for "x" +-- will be in the global env, not the local one. + tcLookupLocalIds :: [Name] -> TcM [TcId] -- We expect the variables to all be bound, and all at -- the same level as the lookup. Only used in one place... -- 1.7.10.4