[GHC] #10707: -fth-dec-file outputs invalid case clauses

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Other Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #10701 Differential Revisions: | -------------------------------------+------------------------------------- instance Data.Aeson.Types.Class.ToJSON Language.Haskell.TH.Syntax.Name where Data.Aeson.Types.Class.toJSON x = \ k_a94l v_a94m -> case k_a94l of { GHC.Base.Just "" -> GHC.Err.undefined GHC.Base.Nothing -> GHC.Err.undefined } (GHC.Base.Just "test") "test2" -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by Fabian): * Attachment "Test.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Revisions: -------------------------------------+------------------------------------- Description changed by Fabian: Old description:
instance Data.Aeson.Types.Class.ToJSON Language.Haskell.TH.Syntax.Name where Data.Aeson.Types.Class.toJSON x = \ k_a94l v_a94m -> case k_a94l of { GHC.Base.Just "" -> GHC.Err.undefined GHC.Base.Nothing -> GHC.Err.undefined } (GHC.Base.Just "test") "test2"
New description: {{{#!hs instance Data.Aeson.Types.Class.ToJSON Language.Haskell.TH.Syntax.Name where Data.Aeson.Types.Class.toJSON x = \ k_a94l v_a94m -> case k_a94l of { GHC.Base.Just "" -> GHC.Err.undefined GHC.Base.Nothing -> GHC.Err.undefined } (GHC.Base.Just "test") "test2" }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by goldfire): * keywords: => newcomer * component: Compiler => Template Haskell * milestone: => 7.12.1 Comment: Thanks for the report. No great care has been made to ensure that pretty- printed Template Haskell can be parsed, but this has been requested before. Straightforward to fix -- all the code is in `Language.Haskell.TH.Ppr`. Anyone care to submit a patch? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by Fabian): * Attachment "Test.hs" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): I'm not sure what you mean by "invalid case clauses", but it seems to me that the error is that {{{ case e of { ...alts... } foo }}} is not valid syntax for an application, it must be parenthesized like {{{ (case e of { ...alts... }) foo }}} A problem with the case expression itself in its context, not the case clauses. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

I'm not sure what you mean by "invalid case clauses", but it seems to me
#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.12.1 Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by Fabian): Replying to [comment:3 rwbarton]: that the error is that
{{{ case e of { ...alts... } foo }}} is not valid syntax for an application, it must be parenthesized like {{{ (case e of { ...alts... }) foo }}} A problem with the case expression itself in its context, not the case clauses.
I wasn't sure exactly what was wrong with the output -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bollmann): Replying to [comment:4 Fabian]:
Replying to [comment:3 rwbarton]:
I'm not sure what you mean by "invalid case clauses", but it seems to me that the error is that {{{ case e of { ...alts... } foo }}} is not valid syntax for an application, it must be parenthesized like {{{ (case e of { ...alts... }) foo }}} A problem with the case expression itself in its context, not the case clauses.
I wasn't sure exactly what was wrong with the output
According to Fabian's specified AST (see the attached Test.hs), the problem rather seems to be missing parentheses around the lambda abstraction as well as missing semi-colons to separate the cases. That is, instead of pretty-printing {{{ instance Data.Aeson.Types.Class.ToJSON Language.Haskell.TH.Syntax.Name where Data.Aeson.Types.Class.toJSON x = \ k_a94l v_a94m -> case k_a94l of { GHC.Base.Just "" -> GHC.Err.undefined GHC.Base.Nothing -> GHC.Err.undefined } (GHC.Base.Just "test") "test2" }}} the code should be pretty-printed as: {{{ instance Data.Aeson.Types.Class.ToJSON Language.Haskell.TH.Syntax.Name where Data.Aeson.Types.Class.toJSON x = (\ k_a94l v_a94m -> case k_a94l of { GHC.Base.Just "" -> GHC.Err.undefined; -- note the ';' here GHC.Base.Nothing -> GHC.Err.undefined }) -- note the parentheses (GHC.Base.Just "test") "test2" }}} That should be easy to fix. I'll have a look. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: bollmann Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bollmann): * owner: => bollmann -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: bollmann Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bollmann): Upon a first investigation, it seems that the pretty printer in `Language.Haskell.TH.Ppr` functions correctly (at least concerning the parentheses around the lambda abstraction). It hence seems as if the pretty printer that is actually called when dumping the splice via -dth-dec-file is not `Language.Haskell.TH.Ppr.pprint`? I will investigate this further... -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: bollmann Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): That may well be true. If I recall, the other pretty-printer to look at is the one for `HsExpr`, in `hsSyn/HsExpr.hs`. It's quite possible that this ticket will be fixed when #10854 is complete. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10707: -fth-dec-file outputs invalid case clauses -------------------------------------+------------------------------------- Reporter: Fabian | Owner: bollmann Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Other | Test Case: Blocked By: | Blocking: Related Tickets: #10701 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bollmann): @goldfire: good reference, thanks! Indeed, applying a lambda abstraction was not correctly parenthesized when converting from TH `Exp`s to `HsExpr`s in `hsSyn/Convert.hs`. However, this has been fixed in #10603. Thus, it would only remain to put semicolons between the different alternatives of the `HsCase` expression in order to make pretty printed code parse again (wrt this particular ticket). It seems to me that adding these ';' could be done by adjusting `pprMatches` in `hsSyn/HsExpr`. But I'm not sure if this rather ad-hoc approach is right, more so since I suspect that there might be other Haskell constructs where the pretty- printer does not print ';' between multiple case alternatives. Any ideas on how to proceed best with this? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10707#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC