Better Template Haskell error message locations
Consider this TH splice
f x = $( [| let g x = (True && 'x', x) in g True |] )
or more generally
f x = $( g [| x |])
- 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
- (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.