[commit: ghc] master: Fix wrapping order in matchExpectedConTy (f7278a9)

git at git.haskell.org git at git.haskell.org
Mon Oct 17 07:42:39 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/f7278a9068dab28f50351c18177cc352d6570285/ghc

>---------------------------------------------------------------

commit f7278a9068dab28f50351c18177cc352d6570285
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Fri Oct 14 17:13:43 2016 +0100

    Fix wrapping order in matchExpectedConTy
    
    The wrappers in matchExpectedConTy were being composed back
    to front, resulting in a Core Lint error.  Yikes!  This has
    been here a long time.
    
    Fixes Trac #12676.


>---------------------------------------------------------------

f7278a9068dab28f50351c18177cc352d6570285
 compiler/typecheck/TcPat.hs                        | 24 +++++++++++++---------
 .../tests/indexed-types/should_compile/T12676.hs   |  9 ++++++++
 testsuite/tests/indexed-types/should_compile/all.T |  1 +
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/compiler/typecheck/TcPat.hs b/compiler/typecheck/TcPat.hs
index dd88992..2f115c6 100644
--- a/compiler/typecheck/TcPat.hs
+++ b/compiler/typecheck/TcPat.hs
@@ -885,21 +885,24 @@ matchExpectedConTy :: PatEnv
                    -> TcM (HsWrapper, [TcSigmaType])
 -- See Note [Matching constructor patterns]
 -- Returns a wrapper : pat_ty "->" T ty1 ... tyn
-matchExpectedConTy (PE { pe_orig = orig }) data_tc pat_ty
+matchExpectedConTy (PE { pe_orig = orig }) data_tc exp_pat_ty
   | Just (fam_tc, fam_args, co_tc) <- tyConFamInstSig_maybe data_tc
          -- Comments refer to Note [Matching constructor patterns]
          -- co_tc :: forall a. T [a] ~ T7 a
-  = do { pat_ty <- expTypeToType pat_ty
-       ; (wrap, pat_ty) <- topInstantiate orig pat_ty
+  = do { pat_ty <- expTypeToType exp_pat_ty
+       ; (wrap, pat_rho) <- topInstantiate orig pat_ty
 
        ; (subst, tvs') <- newMetaTyVars (tyConTyVars data_tc)
              -- tys = [ty1,ty2]
 
        ; traceTc "matchExpectedConTy" (vcat [ppr data_tc,
                                              ppr (tyConTyVars data_tc),
-                                             ppr fam_tc, ppr fam_args])
-       ; co1 <- unifyType noThing (mkTyConApp fam_tc (substTys subst fam_args)) pat_ty
-             -- co1 : T (ty1,ty2) ~N pat_ty
+                                             ppr fam_tc, ppr fam_args,
+                                             ppr exp_pat_ty,
+                                             ppr pat_ty,
+                                             ppr pat_rho, ppr wrap])
+       ; co1 <- unifyType noThing (mkTyConApp fam_tc (substTys subst fam_args)) pat_rho
+             -- co1 : T (ty1,ty2) ~N pat_rho
              -- could use tcSubType here... but it's the wrong way round
              -- for actual vs. expected in error messages.
 
@@ -907,12 +910,13 @@ matchExpectedConTy (PE { pe_orig = orig }) data_tc pat_ty
              co2 = mkTcUnbranchedAxInstCo co_tc tys' []
              -- co2 : T (ty1,ty2) ~R T7 ty1 ty2
 
-       ; return ( wrap <.> (mkWpCastR $
-                            mkTcSubCo (mkTcSymCo co1) `mkTcTransCo` co2)
-                , tys') }
+             full_co = mkTcSubCo (mkTcSymCo co1) `mkTcTransCo` co2
+             -- full_co :: pat_rho ~R T7 ty1 ty2
+
+       ; return ( mkWpCastR full_co <.> wrap, tys') }
 
   | otherwise
-  = do { pat_ty <- expTypeToType pat_ty
+  = do { pat_ty <- expTypeToType exp_pat_ty
        ; (wrap, pat_rho) <- topInstantiate orig pat_ty
        ; (coi, tys) <- matchExpectedTyConApp data_tc pat_rho
        ; return (mkWpCastN (mkTcSymCo coi) <.> wrap, tys) }
diff --git a/testsuite/tests/indexed-types/should_compile/T12676.hs b/testsuite/tests/indexed-types/should_compile/T12676.hs
new file mode 100644
index 0000000..feb1403
--- /dev/null
+++ b/testsuite/tests/indexed-types/should_compile/T12676.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE RankNTypes, TypeFamilies #-}
+
+module T12676 where
+
+data family T a
+data instance T () = MkT
+
+foo :: (forall s. T ()) -> ()
+foo MkT = ()
diff --git a/testsuite/tests/indexed-types/should_compile/all.T b/testsuite/tests/indexed-types/should_compile/all.T
index eab93ac..05c9ad3 100644
--- a/testsuite/tests/indexed-types/should_compile/all.T
+++ b/testsuite/tests/indexed-types/should_compile/all.T
@@ -276,3 +276,4 @@ test('T11581', normal, compile, [''])
 test('T12175', normal, compile, [''])
 test('T12522', normal, compile, [''])
 test('T12522b', normal, compile, [''])
+test('T12676', normal, compile, [''])



More information about the ghc-commits mailing list