summaryrefslogtreecommitdiff
path: root/testsuite/tests/deriving
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2017-07-26 08:51:47 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2017-07-26 12:33:42 +0100
commit75bf11c037d9e82f95ac9779bfd2b1432835bd76 (patch)
tree896e4585202593c1721180ee8f47ae3fb75a0500 /testsuite/tests/deriving
parent746ab0b4a2f97d9f2a97fc28431e5bdfbc10b8cf (diff)
downloadhaskell-75bf11c037d9e82f95ac9779bfd2b1432835bd76.tar.gz
Fix binder visiblity for default methods
Trac #13998 showed that default methods were getting bogus tyvar binder visiblity info; and that it matters in the code genreated by the default-method fill-in mechanism * The actual fix: in TcTyDecls.mkDefaultMethodType, make TyVarBinders with the right visibility info by getting TyConBinders from the class TyCon. (Previously we made up visiblity info, but that caused #13998.) * Define TyCon.tyConTyVarBinders :: [TyConBinder] -> [TyVarBinder] which can build correct forall binders for a) default methods (Trac #13998) b) data constructors This was originally BuildTyCl.mkDataConUnivTyVarBinders * Move mkTyVarBinder, mkTyVarBinders from Type to Var
Diffstat (limited to 'testsuite/tests/deriving')
-rw-r--r--testsuite/tests/deriving/should_compile/T13998.hs43
-rw-r--r--testsuite/tests/deriving/should_compile/all.T1
2 files changed, 44 insertions, 0 deletions
diff --git a/testsuite/tests/deriving/should_compile/T13998.hs b/testsuite/tests/deriving/should_compile/T13998.hs
new file mode 100644
index 0000000000..565d4a35f7
--- /dev/null
+++ b/testsuite/tests/deriving/should_compile/T13998.hs
@@ -0,0 +1,43 @@
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE DefaultSignatures #-}
+{-# LANGUAGE GADTs #-}
+
+module T13998 where
+
+import Data.Type.Equality
+
+class EqForall f where
+ eqForall :: f a -> f a -> Bool
+
+class EqForall f => EqForallPoly f where
+ eqForallPoly :: f a -> f b -> Bool
+ default eqForallPoly :: TestEquality f => f a -> f b -> Bool
+ eqForallPoly = defaultEqForallPoly
+
+defaultEqForallPoly :: (TestEquality f, EqForall f) => f a -> f b -> Bool
+defaultEqForallPoly x y = case testEquality x y of
+ Nothing -> False
+ Just Refl -> eqForall x y
+
+
+data Atom = AtomInt | AtomString | AtomBool
+
+data Value (a :: Atom) where
+ ValueInt :: Int -> Value 'AtomInt
+ ValueString :: String -> Value 'AtomString
+ ValueBool :: Bool -> Value 'AtomBool
+
+instance TestEquality Value where
+ testEquality (ValueInt _) (ValueInt _) = Just Refl
+ testEquality (ValueString _) (ValueString _) = Just Refl
+ testEquality (ValueBool _) (ValueBool _) = Just Refl
+ testEquality _ _ = Nothing
+
+instance EqForall Value where
+ eqForall (ValueInt a) (ValueInt b) = a == b
+ eqForall (ValueString a) (ValueString b) = a == b
+ eqForall (ValueBool a) (ValueBool b) = a == b
+
+instance EqForallPoly Value
diff --git a/testsuite/tests/deriving/should_compile/all.T b/testsuite/tests/deriving/should_compile/all.T
index 7c7b29070b..0025d25dee 100644
--- a/testsuite/tests/deriving/should_compile/all.T
+++ b/testsuite/tests/deriving/should_compile/all.T
@@ -93,3 +93,4 @@ test('drv-empty-data', [normalise_errmsg_fun(just_the_deriving)],compile, ['-ddu
test('drv-phantom', [normalise_errmsg_fun(just_the_deriving)],compile, ['-ddump-deriv -dsuppress-uniques'])
test('T13813', normal, compile, [''])
test('T13919', normal, compile, [''])
+test('T13998', normal, compile, [''])