Re: [GHC] #7918: SrcSpan's associated with expanded quasi-quotes are inconsistent

#7918: SrcSpan's associated with expanded quasi-quotes are inconsistent -------------------------------------+------------------------------------ Reporter: edsko | Owner: edsko Type: bug | Status: new Priority: high | Milestone: 7.8.1 Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by edsko): So here's what's happening: we have {{{ runQuasiQuoteExpr :: HsQuasiQuote RdrName -> RnM (LHsExpr RdrName) }}} which executes a quasi-quote. Note that `runQuasiQuoteExpr` returns a ''located'' expression; it makes an attempt to set the location of the expanded quasi-quote to something sensible. However, `runQuasiQuoteExpr` gets called by `rnExpr`, which ''ignores'' the outermost location returned by `runQuasiQuoteExpr`: {{{ rnExpr (HsQuasiQuoteE qq) = runQuasiQuoteExpr qq `thenM` \ (L _ expr') -> rnExpr expr' }}} The result is that the outermost location is whatever location of the quasi-quote was, while all inner locations have been set by `runQuasiQuoteExpr`. That's why in the test case the case of a single `True` or `False` is different from a compound expression; in all cases the `runQuasiQuoteExpr` sets the location of all identifiers to the same thing, but in the case of a non-compound expression (a single `True` or `False`) this is then overwritten by `rnExpr`; for the compound expression it's the location of the compound expression (`HsApp` or `HsPar`) which gets overwritten instead. Now, we can fix this by adding a special case to `rnLExpr` instead: {{{ rnLExpr :: LHsExpr RdrName -> RnM (LHsExpr Name, FreeVars) -- Don't ignore the new location set by runQuasiQuoteExpr (#7918) #ifndef GHCI rnLExpr (L _ e@(HsQuasiQuoteE _)) = pprPanic "Cant do quasiquotation without GHCi" (ppr e) #else rnLExpr (L loc (HsQuasiQuoteE qq)) = setSrcSpan loc $ runQuasiQuoteExpr qq `thenM` rnLExpr #endif /* GHCI */ rnLExpr e = wrapLocFstM rnExpr e }}} I have done this and it works and it fixes the problem for the case of expressions. I've done it too for the case of types but there seems to be another location override in that case; still looking for that. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/7918#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC