Fix scoped type variables for expression type signatures
[ghc-hetmet.git] / compiler / deSugar / Match.lhs
index 641c2ca..b40bb53 100644 (file)
@@ -254,7 +254,7 @@ match :: [Id]                 -- Variables rep'ing the exprs we're matching with
       -> DsM MatchResult  -- Desugared result!
 
 match [] ty eqns
-  = ASSERT( not (null eqns) )
+  = ASSERT2( not (null eqns), ppr ty )
     returnDs (foldr1 combineMatchResults match_results)
   where
     match_results = [ ASSERT( null (eqn_pats eqn) ) 
@@ -305,7 +305,7 @@ matchCoercion :: [Id] -> Type -> [EquationInfo] -> DsM MatchResult
 matchCoercion (var:vars) ty (eqn1:eqns)
   = do { let CoPat co pat _ = firstPat eqn1
        ; var' <- newUniqueId (idName var) (hsPatType pat)
-       ; match_result <- match (var:vars) ty (map shift (eqn1:eqns))
+       ; match_result <- match (var':vars) ty (map shift (eqn1:eqns))
        ; rhs <- dsCoercion co (return (Var var))
        ; return (mkCoLetMatchResult (NonRec var' rhs) match_result) }
   where
@@ -392,7 +392,7 @@ tidy1 :: Id                         -- The Id being scrutinised
 
 tidy1 v (ParPat pat)      = tidy1 v (unLoc pat) 
 tidy1 v (SigPatOut pat _) = tidy1 v (unLoc pat) 
-tidy1 v (WildPat ty)      = returnDs (idWrapper, WildPat ty)
+tidy1 v (WildPat ty)      = returnDs (idDsWrapper, WildPat ty)
 
        -- case v of { x -> mr[] }
        -- = case v of { _ -> let x=v in mr[] }
@@ -427,7 +427,7 @@ tidy1 v (LazyPat pat)
        ; returnDs (mkDsLets sel_binds, WildPat (idType v)) }
 
 tidy1 v (ListPat pats ty)
-  = returnDs (idWrapper, unLoc list_ConPat)
+  = returnDs (idDsWrapper, unLoc list_ConPat)
   where
     list_ty     = mkListTy ty
     list_ConPat = foldr (\ x y -> mkPrefixConPat consDataCon [x, y] list_ty)
@@ -437,13 +437,13 @@ tidy1 v (ListPat pats ty)
 -- Introduce fake parallel array constructors to be able to handle parallel
 -- arrays with the existing machinery for constructor pattern
 tidy1 v (PArrPat pats ty)
-  = returnDs (idWrapper, unLoc parrConPat)
+  = returnDs (idDsWrapper, unLoc parrConPat)
   where
     arity      = length pats
     parrConPat = mkPrefixConPat (parrFakeCon arity) pats (mkPArrTy ty)
 
 tidy1 v (TuplePat pats boxity ty)
-  = returnDs (idWrapper, unLoc tuple_ConPat)
+  = returnDs (idDsWrapper, unLoc tuple_ConPat)
   where
     arity = length pats
     tuple_ConPat = mkPrefixConPat (tupleCon boxity arity) pats ty
@@ -459,16 +459,16 @@ tidy1 v (DictPat dicts methods)
 
 -- LitPats: we *might* be able to replace these w/ a simpler form
 tidy1 v (LitPat lit)
-  = returnDs (idWrapper, tidyLitPat lit)
+  = returnDs (idDsWrapper, tidyLitPat lit)
 
 -- NPats: we *might* be able to replace these w/ a simpler form
 tidy1 v (NPat lit mb_neg eq lit_ty)
-  = returnDs (idWrapper, tidyNPat lit mb_neg eq lit_ty)
+  = returnDs (idDsWrapper, tidyNPat lit mb_neg eq lit_ty)
 
 -- Everything else goes through unchanged...
 
 tidy1 v non_interesting_pat
-  = returnDs (idWrapper, non_interesting_pat)
+  = returnDs (idDsWrapper, non_interesting_pat)
 \end{code}
 
 \noindent
@@ -715,6 +715,9 @@ data PatGroup
 
 
 groupEquations :: [EquationInfo] -> [[(PatGroup, EquationInfo)]]
+-- If the result is of form [g1, g2, g3], 
+-- (a) all the (pg,eq) pairs in g1 have the same pg
+-- (b) none of the gi are empty
 groupEquations eqns
   = runs same_gp [(patGroup (firstPat eqn), eqn) | eqn <- eqns]
   where
@@ -745,6 +748,10 @@ sameGroup (PgN l1)   (PgN l2)   = True             -- Needs conditionals
 sameGroup (PgNpK l1) (PgNpK l2) = l1==l2       -- Order is significant
                                                -- See Note [Order of n+k]
 sameGroup (PgCo        t1)  (PgCo t2)  = t1 `coreEqType` t2
+       -- CoPats are in the same goup only if the type of the
+       -- enclosed pattern is the same. The patterns outside the CoPat
+       -- always have the same type, so this boils down to saying that
+       -- the two coercions are identical.
 sameGroup _          _          = False
  
 patGroup :: Pat Id -> PatGroup