[GHC] #10330: Better Template Haskell error message locations

#10330: Better Template Haskell error message locations -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template | Version: 7.10.1 Haskell | Operating System: Unknown/Multiple Keywords: | Type of failure: None/Unknown Architecture: | Blocked By: Unknown/Multiple | Related Tickets: Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Consider this TH splice {{{ f x = $( [| let g x = (True && 'x', x) in g True |] ) }}} or more generally {{{ f x = $( g [| x |]) }}} Two problems 1. If there is a type error in the spliced-in code, there is no record of the splice in the error message: {{{ TH.hs:5:10: Couldn't match expected type ‘Bool’ with actual type ‘Char’ In the second argument of ‘(&&)’, namely ‘'x'’ In the expression: (True && 'x') In the expression: ((True && 'x'), x_a2qf) }}} I'd like to see {{{ TH.hs:5:10: Couldn't match expected type ‘Bool’ with actual type ‘Char’ In the second argument of ‘(&&)’, namely ‘'x'’ In the expression: (True && 'x') In the splice: $( [| let g x = ... in g True |] ) <------- NB }}} 2. (Less important, and harder to fix.) The error location (column 10) is that of the splice (column 10), not where the reported error really is (column 31). Fixing this would mean round-tripping source location info through TH syntax. Moreover, since the constructed code may be combined from quoted snippets spread over some TH libraries, it's far from clear that the location info would help. Thoughts about fixing (1). This can only arise for untyped splices. (For typed splices we can't get type errors in spliced code.) So the renamer should produce a syntax tree with a variant of `HsPar` saying "here is where I spliced in an expression". Same think for patterns and types; for declarations it would be a bit more fiddly. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10330 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10330: Better Template Haskell error message locations -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): In my opinion, (2) above is more important than (1). The `singletons` package encourages wrapping up lots of code in one big splice and quote. (`$(singletons [d| data Foo = ... ; bar :: ...; bar = ...; ... |])`) Because of the bug reported here, users get no location information attached to often-baroque errors. Agreed that (2) is quite a bit harder to fix than (1), though. (2) would seem to require a full overhaul of the TH AST and would break many clients of TH. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10330#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10330: Better Template Haskell error message locations -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by ezyang): In that case, let me record one possible workaround for problem (2), which is #10331; however, this doesn't help users of the old TH API. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10330#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10330: Better Template Haskell error message locations -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by ezyang): * cc: ezyang (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10330#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC