Commit f7f9820e authored by wz1000's avatar wz1000 Committed by Krzysztof Gogolewski

Check if files are same in combineSrcSpans

Summary: If this is not checked, SrcSpans are sometimes mangled by CPP.

Test Plan: ./validate

Reviewers: bgamari, dfeuer

Reviewed By: bgamari

Subscribers: dfeuer, rwbarton, thomie, carter

GHC Trac Issues: #15279

Differential Revision: https://phabricator.haskell.org/D4866
parent d42eef34
......@@ -307,12 +307,14 @@ mkSrcSpan (RealSrcLoc loc1) (RealSrcLoc loc2)
= RealSrcSpan (mkRealSrcSpan loc1 loc2)
-- | Combines two 'SrcSpan' into one that spans at least all the characters
-- within both spans. Assumes the "file" part is the same in both inputs
-- within both spans. Returns UnhelpfulSpan if the files differ.
combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpan
combineSrcSpans (UnhelpfulSpan _) r = r -- this seems more useful
combineSrcSpans l (UnhelpfulSpan _) = l
combineSrcSpans (RealSrcSpan span1) (RealSrcSpan span2)
= RealSrcSpan (combineRealSrcSpans span1 span2)
| srcSpanFile span1 == srcSpanFile span2
= RealSrcSpan (combineRealSrcSpans span1 span2)
| otherwise = UnhelpfulSpan (fsLit "<combineSrcSpans: files differ>")
-- | Combines two 'SrcSpan' into one that spans at least all the characters
-- within both spans. Assumes the "file" part is the same in both inputs
......
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -ddump-parsed-ast #-}
module T15279 where
foo :: Char -> Char
#include "T15279.hs-incl"
foo _ = 'a'
(MG
(NoExt)
({ <combineSrcSpans: files differ> }
......@@ -117,3 +117,16 @@ test('T13986', normal, compile, [''])
test('T10855', normal, compile, [''])
test('T15139', normal, compile, ['-Wincomplete-patterns -fdiagnostics-show-caret'])
test('T15323', normal, compile, ['-dsuppress-uniques -ddump-parsed-ast'])
def only_MG_loc(x):
"""
Only compares the location embedded inside the MatchGroup, which has the form
(MG
(NoExt)
({ <location>
"""
ls = x.split("\n")
mgLocs = (loc.strip() for (mg,loc) in zip(ls,ls[2:])
if mg.strip().startswith("(MG"))
return '\n'.join(mgLocs)
test('T15279', normalise_errmsg_fun(only_MG_loc), compile, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment