The Core type-matcher should look through PredTypes
authorsimonpj@microsoft.com <unknown>
Wed, 16 Jan 2008 14:59:39 +0000 (14:59 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 16 Jan 2008 14:59:39 +0000 (14:59 +0000)
The core type-matcher Unify.match was previouly using tcView to expand
types, because it must treat newtypes as distinct from their representation.
But that meant that it also treated the PredType {C Int} as distinct from
its representation type (:TC Int).  And that in turn was causing a rule
not to fire, because the argument types didn't match up.

For this to happen we need to get a situation where we have

  a = :DC blah blah -- Dictionary
  ....(f a).....

Now a has type (:TC Int), bu the RULE for f expects an argument
of type {C Int}.  Roman found that just this was happening.

compiler/types/Unify.lhs

index 8ffee89..b99d387 100644 (file)
@@ -146,11 +146,12 @@ match :: MatchEnv -- For the most part this is pushed downwards
                        --      in-scope set of the RnEnv2
       -> Type -> Type  -- Template and target respectively
       -> Maybe TvSubstEnv
--- This matcher works on source types; that is, 
--- it respects NewTypes and PredType
+-- This matcher works on core types; that is, it ignores PredTypes
+-- Watch out if newtypes become transparent agin!
+--     this matcher must respect newtypes
 
-match menv subst ty1 ty2 | Just ty1' <- tcView ty1 = match menv subst ty1' ty2
-                        | Just ty2' <- tcView ty2 = match menv subst ty1 ty2'
+match menv subst ty1 ty2 | Just ty1' <- coreView ty1 = match menv subst ty1' ty2
+                        | Just ty2' <- coreView ty2 = match menv subst ty1 ty2'
 
 match menv subst (TyVarTy tv1) ty2
   | tv1' `elemVarSet` me_tmpls menv