diff options
author | RyanGlScott <ryan.gl.scott@gmail.com> | 2015-10-03 20:06:48 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-10-03 20:36:34 +0200 |
commit | 2f74be9c8af1e167b21df1a27b96b6626cd446a9 (patch) | |
tree | b993d2b8c2efdc00081f6243bc744fd0d2ad3bae /testsuite/tests/generics | |
parent | 0eb8fcd94b29ee9997b386e64203037bdf2aaa04 (diff) | |
download | haskell-2f74be9c8af1e167b21df1a27b96b6626cd446a9.tar.gz |
Fill in associated type defaults with DeriveAnyClass
Summary:
Unlike `-XDefaultSignatures`, `-XDeriveAnyClass` would not fill in
associated type family defaults when deriving a class which contained
them.
In order to fix this properly, `tcATDefault` needed to be used from
`TcGenDeriv`. To avoid a module import cycle, `tcATDefault` was moved
from `TcInstDcls` to `TcClsDcl`.
Fixes #10361.
Test Plan: ./validate
Reviewers: kosmikus, dreixel, bgamari, austin, simonpj
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1283
GHC Trac Issues: #10361
Diffstat (limited to 'testsuite/tests/generics')
-rw-r--r-- | testsuite/tests/generics/T10361a.hs | 32 | ||||
-rw-r--r-- | testsuite/tests/generics/T10361b.hs | 58 | ||||
-rw-r--r-- | testsuite/tests/generics/all.T | 2 |
3 files changed, 92 insertions, 0 deletions
diff --git a/testsuite/tests/generics/T10361a.hs b/testsuite/tests/generics/T10361a.hs new file mode 100644 index 0000000000..cc5fbb9dca --- /dev/null +++ b/testsuite/tests/generics/T10361a.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TypeFamilies #-} +module T10361a where + +class C1 a where + type T1 a + type instance T1 a = Char + +class C2 a where -- equivalent to C1 + type T2 a + type instance T2 a = Char + +class C3 a where -- equivalent to C1, C2 + type T3 a + type instance T3 a = Char + +data A = B + deriving C1 + +deriving instance C2 A + +instance C3 A + +test1 :: T1 A +test1 = 'x' + +test2 :: T2 A +test2 = 'x' + +test3 :: T3 A +test3 = 'x' diff --git a/testsuite/tests/generics/T10361b.hs b/testsuite/tests/generics/T10361b.hs new file mode 100644 index 0000000000..6ecd99e644 --- /dev/null +++ b/testsuite/tests/generics/T10361b.hs @@ -0,0 +1,58 @@ +{-# LANGUAGE DefaultSignatures #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE UndecidableInstances #-} + +module T10361b where + +import GHC.Generics + +--------------------------------------------------------------------- +class Convert a where + type Result a + type instance Result a = GResult (Rep a) + + convert :: a -> Result a + default convert :: (Generic a, GConvert (Rep a)) => a -> GResult (Rep a) + convert x = gconvert (from x) + +instance Convert Float where + type Result Float = Float + convert = id + +instance Convert Int where + type Result Int = Int + convert = id + +--------------------------------------------------------------------- +class GConvert f where + type GResult f + gconvert :: f p -> GResult f + +instance (Convert c) => GConvert (K1 i c) where + type GResult (K1 i c) = Result c + gconvert (K1 x) = convert x + +instance (GConvert f) => GConvert (M1 i t f) where + type GResult (M1 i t f) = GResult f + gconvert (M1 x) = gconvert x + +instance (GConvert f, GConvert g) => GConvert (f :*: g) where + type GResult (f :*: g) = (GResult f, GResult g) + gconvert (x :*: y) = (gconvert x, gconvert y) + +--------------------------------------------------------------------- + +data Data1 = Data1 Int Float + deriving (Generic) + +instance Convert Data1 + +val :: (Int, Float) +val = convert $ Data1 0 0.0 + +data Data2 = Data2 Int Float + deriving (Generic, Convert) diff --git a/testsuite/tests/generics/all.T b/testsuite/tests/generics/all.T index 31a6809c82..cbf70cf8bf 100644 --- a/testsuite/tests/generics/all.T +++ b/testsuite/tests/generics/all.T @@ -40,3 +40,5 @@ test('T8468', normal, compile_fail, ['']) test('T8479', normal, compile, ['']) test('T9563', normal, compile, ['']) test('T10030', normal, compile_and_run, ['']) +test('T10361a', normal, compile, ['']) +test('T10361b', normal, compile, ['']) |