Fix ASSERT in buildPatSyn, and T10897 test
authorSimon Peyton Jones <simonpj@microsoft.com>
Wed, 23 Dec 2015 10:13:26 +0000 (10:13 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Wed, 23 Dec 2015 10:14:02 +0000 (10:14 +0000)
This closes Trac #10897

compiler/iface/BuildTyCl.hs
testsuite/tests/patsyn/should_compile/T10897.hs [moved from testsuite/tests/patsyn/should_compile/T10897b.hs with 61% similarity]
testsuite/tests/patsyn/should_compile/all.T

index 7c62bc2..d370d37 100644 (file)
@@ -182,12 +182,14 @@ buildPatSyn :: Name -> Bool
 buildPatSyn src_name declared_infix matcher@(matcher_id,_) builder
             (univ_tvs, req_theta) (ex_tvs, prov_theta) arg_tys
             pat_ty field_labels
-  = ASSERT2((and [ univ_tvs == univ_tvs1
-                 , ex_tvs == ex_tvs1
-                 , pat_ty `eqType` pat_ty1
-                 , prov_theta `eqTypes` prov_theta1
-                 , req_theta `eqTypes` req_theta1
-                 , arg_tys `eqTypes` arg_tys1
+  = -- The assertion checks that the matcher is
+    -- compatible with the pattern synonym
+    ASSERT2((and [ univ_tvs `equalLength` univ_tvs1
+                 , ex_tvs `equalLength` ex_tvs1
+                 , pat_ty `eqType` substTy subst pat_ty1
+                 , prov_theta `eqTypes` substTys subst prov_theta1
+                 , req_theta `eqTypes` substTys subst req_theta1
+                 , arg_tys `eqTypes` substTys subst arg_tys1
                  ])
             , (vcat [ ppr univ_tvs <+> twiddle <+> ppr univ_tvs1
                     , ppr ex_tvs <+> twiddle <+> ppr ex_tvs1
@@ -205,6 +207,8 @@ buildPatSyn src_name declared_infix matcher@(matcher_id,_) builder
     (ex_tvs1, prov_theta1, cont_tau) = tcSplitSigmaTy cont_sigma
     (arg_tys1, _) = tcSplitFunTys cont_tau
     twiddle = char '~'
+    subst = zipTopTCvSubst (univ_tvs1 ++ ex_tvs1)
+                           (mkTyVarTys (univ_tvs ++ ex_tvs))
 
 ------------------------------------------------------
 type TcMethInfo = (Name, Type, Maybe (DefMethSpec Type))
index dd2bbf4..e1c8243 100644 (file)
@@ -41,8 +41,8 @@ test('poly-export3', normal, compile, [''])
 test('multi-export', normal, compile, [''])
 test('export-super-class', normal, compile, [''])
 test('export-record-selector', normal, compile, [''])
-test('T10897', expect_broken(10897), multi_compile, ['T10897', [
+test('T10897', normal, multi_compile, ['T10897', [
                                        ('T10897a.hs','-c')
-                                      ,('T10897b.hs', '-c')], ''])
+                                      ], '-v0'])
 test('T11224b', normal, compile, [''])
 test('MoreEx', normal, compile, [''])