goldfirere / th-desugar

Desugars Template Haskell abstract syntax to a simpler format without changing semantics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent treatment of unsupported language features in L.H.TH.Desugar.Sweeten

RyanGlScott opened this issue · comments

In most parts of th-desugar, any code that deals with an unsupported language feature will simply throw an error. Here is an example from L.H.TH.Desugar.Core:

dsPat (ViewP _ _) =
fail "View patterns are not supported in th-desugar. Use pattern guards instead."

And from L.H.TH.Desugar.Sweeten:

#if __GLASGOW_HASKELL__ < 709
expToTH (DStaticE _) = error "Static expressions supported only in GHC 7.10+"
#else

However, this convention is not applied uniformly in L.H.TH.Desugar.Sweeten. There is one particular function, pragmaToTH, that returns a Maybe rather than erroring out on unsupported language features:

#if __GLASGOW_HASKELL__ < 709
pragmaToTH (DLineP {}) = Nothing
#else
pragmaToTH (DLineP n str) = Just $ LineP n str
#endif

This has a ripple effect on several other type signatures in L.H.TH.Desugar.Sweeten. For instance, the type of decToTH is DDec -> [Dec] instead the more sensible DDec -> Dec.

I propose that we change pragmaToTH to error out on unsupported pragmas, which would allow simplifying its type to DPragma -> Pragma, enabling other simplifications elsewhere in the module.