derive icon indicating copy to clipboard operation
derive copied to clipboard

Could not convert Dec to Decl ()

Open blackgnezdo opened this issue 6 years ago • 2 comments

Running derive/v2_6_2 with GHC8 I'm getting this error:

Bug2.hs:1:1: error:
    Exception when trying to run compile-time code:
      Could not convert Dec to Decl ()
TySynD Main.NewType [] (ConT Main.DataType)
derive/v2_6_2/src/Language/Haskell/Convert.hs:(41,14)-(45,8): Non-exhaustive patterns in case

CallStack (from HasCallStack):
derive/v2_6_2/src/Language/Haskell/Convert.hs:22:87 in derive:Language.Haskell.Convert
    Code: derive makeNFData ''NewType

for the code below:

{-# LANGUAGE TemplateHaskell #-}

import Control.DeepSeq(NFData(..))
import Data.DeriveTH

type NewType = DataType
data DataType = DataType
$(derive makeNFData ''NewType)

Admittedly deriving something for a type is not exactly the best idea, but a more helpful error would be nice.

blackgnezdo avatar Oct 31 '17 04:10 blackgnezdo

Come to think of it, the issue is not in fact silly. In full code my data is parameterized by a type family. So I do need to derive the instance for the type Type = DataType Identity. Making this work is a functional requirement.

FWIW, this workaround kind of works, but I loathe mixing different styles of NFData:

deriving instance Generic Type
instance NFData Type

blackgnezdo avatar Oct 31 '17 04:10 blackgnezdo

Warning: This package has no official maintainer anymore. Use at your own risk. You may wish to consider the built-in mechanism GHC.Generics or libraries such as generic-deriving.

ndmitchell avatar Jul 05 '18 09:07 ndmitchell