ndmitchell / derive

A Haskell program and library to derive instances for data types
BSD 3-Clause "New" or "Revised" License
25 stars 17 forks source link

Could not convert Dec to Decl #18

Closed tamarit closed 8 years ago

tamarit commented 8 years ago

Hi Neil or hi new maintainer,

I've trying to derive some type automatically using this fantastic tool. For simple examples it works fine, but when I get it into "real life", I'm getting this error constantly. I've been googling and somewhere someone says that this is a bug in your code. Is this true?

 Exception when trying to run compile-time code:
      Could not convert Dec to Decl
TySynD RulesLib.CStatAnn [] (AppT (ConT Language.C.Syntax.AST.CStatement) (AppT (AppT (ConT RulesLib.Annotation) (ConT Language.C.Data.Node.NodeInfo)) (ConT RulesLib.NodeProperties)))
src/Language/Haskell/Convert.hs:(39,14)-(49,8): Non-exhaustive patterns in case

    Code: derive makeBinary ''CStatAnn

Thanks in advance Salva

ndmitchell commented 8 years ago

The problem in this case is that CStatAnn is a type alias, defined with type CStatAnn = .... You should not define instances for type aliases, but should instead define them for the data types like CStatement.

Certainly could be a better error message!

tamarit commented 8 years ago

Ah ok. I didn't know that sorry. Makes sense :)

Thank Neil for the info. Salva