diff options
author | RyanGlScott <ryan.gl.scott@gmail.com> | 2016-01-06 12:05:05 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-01-06 12:05:12 +0100 |
commit | 852b603029a047609a54453b1f9cd65035a43afe (patch) | |
tree | 6cb96f24dcf4a2f1ac747525ac618afa86689abb /testsuite/tests/generics | |
parent | 4dc4b8445710d92d23505b875a8d666217bc932d (diff) | |
download | haskell-852b603029a047609a54453b1f9cd65035a43afe.tar.gz |
Restore old GHC generics behavior vis-à-vis Fixity
Phab:D493 accidentally changed the way GHC generics looks up `Fixity`
information when deriving `Generic` or `Generic1`. Before, a `Fixity` of
`Infix` would be given only if a data constructor was declared infix,
but now, `Infix` is given to any data constructor that has a fixity
declaration (not to be confused with being declared infix!). This commit
reverts back to the original behavior for consistency's sake.
Fixes #11358.
Test Plan: ./validate
Reviewers: kosmikus, dreixel, austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1740
GHC Trac Issues: #11358
Diffstat (limited to 'testsuite/tests/generics')
-rw-r--r-- | testsuite/tests/generics/T11358.hs | 32 | ||||
-rw-r--r-- | testsuite/tests/generics/T11358.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/generics/all.T | 3 |
3 files changed, 35 insertions, 1 deletions
diff --git a/testsuite/tests/generics/T11358.hs b/testsuite/tests/generics/T11358.hs new file mode 100644 index 0000000000..8f52d5ce68 --- /dev/null +++ b/testsuite/tests/generics/T11358.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE DefaultSignatures #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +module Main (main) where + +import GHC.Generics + +infixr 1 `T` +data T a = T a a deriving Generic +instance HasFixity (T a) + +data I a = a `I` a deriving Generic +instance HasFixity (I a) + +class HasFixity a where + fixity :: a -> Fixity + default fixity :: (Generic a, GHasFixity (Rep a)) => a -> Fixity + fixity = gfixity . from + +class GHasFixity f where + gfixity :: f a -> Fixity + +instance GHasFixity f => GHasFixity (D1 d f) where + gfixity (M1 x) = gfixity x + +instance Constructor c => GHasFixity (C1 c f) where + gfixity c = conFixity c + +main :: IO () +main = do + putStrLn $ show (fixity (T "a" "b")) ++ ", " ++ show (fixity ("a" `I` "b")) diff --git a/testsuite/tests/generics/T11358.stdout b/testsuite/tests/generics/T11358.stdout new file mode 100644 index 0000000000..f7b347d9af --- /dev/null +++ b/testsuite/tests/generics/T11358.stdout @@ -0,0 +1 @@ +Prefix, Infix LeftAssociative 9 diff --git a/testsuite/tests/generics/all.T b/testsuite/tests/generics/all.T index 32534834f2..cae975c89e 100644 --- a/testsuite/tests/generics/all.T +++ b/testsuite/tests/generics/all.T @@ -35,7 +35,7 @@ test('GenDerivOutput1_1', normal, compile, ['-dsuppress-uniques']) test('T7878', extra_clean(['T7878A.o' ,'T7878A.hi' ,'T7878A.o-boot','T7878A.hi-boot' - ,'T7878B.o' ,'T7878B.hi']), + ,'T7878B.o' ,'T7878B.hi']), multimod_compile, ['T7878', '-v0']) test('T8468', normal, compile_fail, ['']) @@ -44,3 +44,4 @@ test('T9563', normal, compile, ['']) test('T10030', normal, compile_and_run, ['']) test('T10361a', normal, compile, ['']) test('T10361b', normal, compile, ['']) +test('T11358', normal, compile_and_run, ['']) |