Skip to content

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 |])

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
  1. (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.

Trac metadata
Trac field Value
Version 7.10.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information