[GHC] #10330: Better Template Haskell error message locations
GHC
ghc-devs at haskell.org
Mon Apr 20 13:34:20 UTC 2015
#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
More information about the ghc-tickets
mailing list