Ticket #7351 (closed bug: fixed)
showRichTokenStream has an off-by one error on starting col
| Reported by: | alanz | Owned by: | simonmar |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.6.2 |
| Component: | GHC API | Version: | 7.6.1 |
| Keywords: | Cc: | ||
| Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
| Type of failure: | None/Unknown | Difficulty: | Unknown |
| Test Case: | Blocked By: | ||
| Blocking: | Related Tickets: |
Description (last modified by simonmar) (diff)
When using showRichTokenStream to re-create a source file, all lines after the first one start one column from the left.
The code for advancing to a new line has an off-by one bug where it assumes zero based columns.
I have marked what I assume to be a fix in the pasted code below.
showRichTokenStream ts = go startLoc ts ""
where sourceFile = getFile $ map (getLoc . fst) ts
getFile [] = panic "showRichTokenStream: No source file found"
getFile (UnhelpfulSpan _ : xs) = getFile xs
getFile (RealSrcSpan s : _) = srcSpanFile s
startLoc = mkRealSrcLoc sourceFile 1 1
go _ [] = id
go loc ((L span _, str):ts)
= case span of
UnhelpfulSpan _ -> go loc ts
RealSrcSpan s
| locLine == tokLine -> ((replicate (tokCol - locCol) ' ') ++)
. (str ++)
. go tokEnd ts
| otherwise -> ((replicate (tokLine - locLine) '\n') ++)
. ((replicate (tokCol - 1) ' ') ++) -- AZ: updated line
. (str ++)
. go tokEnd ts
where (locLine, locCol) = (srcLocLine loc, srcLocCol loc)
(tokLine, tokCol) = (srcSpanStartLine s, srcSpanStartCol s)
tokEnd = realSrcSpanEnd s
Change History
Note: See
TracTickets for help on using
tickets.
