haskell-suite / haskell-src-exts

Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer
Other
193 stars 94 forks source link

Failure to parse record-style GADT constructors in the presence of constructor constraints #404

Closed thoughtpolice closed 6 years ago

thoughtpolice commented 6 years ago

Consider the following:

{-# LANGUAGE GADTs #-}

data T a where
  C :: () => Int -> T a

This works fine:

$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Prelude> import Language.Haskell.Exts
Prelude Language.Haskell.Exts> parseFile "/home/aseipp/t/GADTConstraintRecord.hs"
ParseOk (Module ...

However, using the record syntax for GADT constructors breaks this. The following does not work:

{-# LANGUAGE GADTs #-}

data T a where
  C :: () => { foo :: Int } -> T a
Prelude Language.Haskell.Exts> parseFile "/home/aseipp/t/GADTConstraintRecord.hs"
ParseFailed (SrcLoc "/home/aseipp/t/GADTConstraintRecord.hs" 4 14) "Parse error: {"

Note that haskell-src-exts does handle record syntax for GADT constructors fine -- if you simply remove () =>, then it will work. It is simply the combination of a constraint and record syntax for the constructor that fails.

Version: haskell-src-exts 1.20.2 (found through usage of stylish-haskell).

thoughtpolice commented 6 years ago

(I updated the title to more accurately reflect the problem, given the parse error: the constraint is handled OK, it is merely the record-style syntax that is unexpected by the parser in the event a constraint is present)