Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • 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,842
    • Issues 4,842
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #14681

Closed
Open
Created Jan 17, 2018 by Ryan Scott@RyanGlScottMaintainer

More incorrect Template Haskell parenthesization

The latest installment of "RyanGlScott finds bugs in Template Haskell pretty-printing". Here is what's featured on today's episode:

{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Bug where

import Data.Functor.Identity
import Language.Haskell.TH

$([d| f = \(Identity x) -> x |])
$([d| g = $(pure $ VarE '(+) `AppE` LitE (IntegerL (-1)) `AppE` (LitE (IntegerL (-1)))) |])

Running this with GHC 8.2 or later yields some incorrectly parenthesized output:

$ /opt/ghc/8.2.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
Bug.hs:8:3-31: Splicing declarations
    [d| f_azO = \ (Identity x_azP) -> x_azP |]
  ======>
    f_a3Nx = \ Identity x_a3Ny -> x_a3Ny
Bug.hs:9:3-90: Splicing declarations
    [d| g_a3NU
          = $(pure
                $ VarE '(+) `AppE` LitE (IntegerL (- 1))
                    `AppE` (LitE (IntegerL (- 1)))) |]
    pending(rn) [<splice_a3NV, pure
                                 $ VarE '(+) `AppE` LitE (IntegerL (- 1))
                                     `AppE` (LitE (IntegerL (- 1)))>]
  ======>
    g_a4dU = ((+) -1) -1

In particular, look at these two lines:

f_a3Nx = \ Identity x_a3Ny -> x_a3Ny
g_a4dU = ((+) -1) -1

These should be:

f_a3Nx = \ (Identity x_a3Ny) -> x_a3Ny
g_a4dU = ((+) (-1)) (-1)
Trac metadata
Trac field Value
Version 8.2.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
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