[project @ 1998-04-07 16:40:08 by simonpj]
[ghc-hetmet.git] / ghc / compiler / simplCore / SimplVar.lhs
index 92cd7cf..30b9381 100644 (file)
@@ -198,12 +198,16 @@ simplBinder env (id, occ_info)
 
        -- id2 has its SpecEnv zapped
        id2 | isEmptySpecEnv spec_env = id1
-           | otherwise               = setIdSpecialisation id spec_env'
+           | otherwise               = setIdSpecialisation id1 spec_env'
     in
     if not_in_scope then
-       -- No need to clone
+       -- No need to clone, but we *must* zap any current substitution
+       -- for the variable.  For example:
+       --      (\x.e) with id_subst = [x |-> e']
+       -- Here we must simply zap the substitution for x
        let
-           env' = setIdEnv env (new_in_scope_ids id2, id_subst)
+           env' = setIdEnv env (new_in_scope_ids id2, 
+                                delOneFromIdEnv id_subst id)
        in
        returnSmpl (env', id2)
     else
@@ -237,9 +241,12 @@ simplBinders env binders = mapAccumLSmpl simplBinder env binders
 \begin{code}   
 simplTyBinder :: SimplEnv -> TyVar -> SmplM (SimplEnv, TyVar)
 simplTyBinder env tyvar
-  | not (tyvar `elementOfTyVarSet` tyvars)     -- No need to clone
-  = let
-       env' = setTyEnv env (tyvars `addOneToTyVarSet` tyvar, ty_subst)
+  | not (tyvar `elementOfTyVarSet` tyvars)
+  =    -- No need to clone; but must zap any binding for tyvar
+       -- see comments with simplBinder above
+    let
+       env' = setTyEnv env (tyvars `addOneToTyVarSet` tyvar, 
+                            delFromTyVarEnv ty_subst tyvar)
     in
     returnSmpl (env', tyvar)