[GHC] #14681: More incorrect Template Haskell parenthesization
#14681: More incorrect Template Haskell parenthesization -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template | Version: 8.2.2 Haskell | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The latest installment of "RyanGlScott finds bugs in Template Haskell pretty-printing". Here is what's featured on today's episode: {{{#!hs {-# 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) }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14681> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14681: More incorrect Template Haskell parenthesization -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4323 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D4323 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14681#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14681: More incorrect Template Haskell parenthesization -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4323 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"575c009d9e4b25384ef984c09b2c54f909693e93/ghc" 575c009d/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="575c009d9e4b25384ef984c09b2c54f909693e93" Fix #14681 and #14682 with precision-aimed parentheses It turns out that `Convert` was recklessly leaving off parentheses in two places: * Negative numeric literals * Patterns in lambda position This patch fixes it by adding three new functions, `isCompoundHsLit`, `isCompoundHsOverLit`, and `isCompoundPat`, and using them in the right places in `Convert`. While I was in town, I also sprinkled `isCompoundPat` among some `Pat`-constructing functions in `HsUtils` to help avoid the likelihood of this problem happening in other places. One of these places is in `TcGenDeriv`, and sprinkling `isCompountPat` there fixes #14682 Test Plan: make test TEST="T14681 T14682" Reviewers: alanz, goldfire, bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14681, #14682 Differential Revision: https://phabricator.haskell.org/D4323 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14681#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14681: More incorrect Template Haskell parenthesization -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Template Haskell | Version: 8.2.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4323 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14681#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC