Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9022
Closed
Open
Created Apr 23, 2014 by roldugin@trac-roldugin

TH pretty printer and GHC parser semicolon placement mismatch

In GHC 7.8 TemplateHaskell pretty printer started inserting explicit braces and semicolons.

It puts semicolons at the end of the line as opposed to the beginning of the next line.

This causes GHC to fail parsing if we try to compile the pretty printed code.

$ cat Foo.hs
module Main where

import Language.Haskell.TH

main = putStrLn $ pprint foo

foo :: Dec
foo = barD
  where
       barD = FunD ( mkName "bar" )
                   [ Clause manyArgs (NormalB barBody) [] ]

       barBody = DoE [letxStmt, retxStmt]

       letxStmt = LetS [ ValD (VarP xName) (NormalB $ LitE $ IntegerL 5) [] ]

       retxStmt = NoBindS $ AppE returnVarE xVarE

       xName = mkName "x"

       returnVarE = VarE $ mkName "return"

       xVarE = VarE xName

       manyArgs = map argP [0..9]

       argP n = VarP $ mkName $ "arg" ++ show n

$ ghc-7.8.2 Foo.hs
[1 of 1] Compiling Main             ( Foo.hs, Foo.o )
Linking Foo ...

$ ./Foo | tee Bar.hs
bar arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 = do {let x = 5;
                                                            return x}

$ ghc Bar.hs
[1 of 1] Compiling Main             ( Bar.hs, Bar.o )

Bar.hs:2:61: parse error on input `return'

I don't know if this is a problem with TH pretty printer or if GHC is supposed to parse semicolons wherever they are..

Trac metadata
Trac field Value
Version 7.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Parser)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking