on master help sign in
Avoid comparing ‘SourceText’ when comparing ASTs
2dfd181mrkkrp
data/examples/declaration/instance/overlappable-instances-out.hs−5
@@ -1,8 +1,3 @@
1−-- Test should have tested different whitespaces inside pragma. However, the
2−-- pragmas contain a "SourceText" which compares as equal only if the whitespace
3−-- inside the pragma is printed exactly identically (i.e. including newlines and
4−-- all.) In practice, removing this whitespace is desirable, so whitespace is
5−-- not varied to avoid spurious and difficult-to-avoid test case errors.
6instance {-# OVERLAPPABLE #-} Eq Int where
1instance {-# OVERLAPPABLE #-} Eq Int where
7 (==) _ _ = False
2 (==) _ _ = False
8
3
data/examples/declaration/instance/overlappable-instances.hs+4−10
@@ -1,17 +1,11 @@
1−-- Test should have tested different whitespaces inside pragma. However, the
2−-- pragmas contain a "SourceText" which compares as equal only if the whitespace
3−-- inside the pragma is printed exactly identically (i.e. including newlines and
4−-- all.) In practice, removing this whitespace is desirable, so whitespace is
5−-- not varied to avoid spurious and difficult-to-avoid test case errors.
6−
7−instance {-# OVERLAPPABLE #-} Eq Int where (==) _ _ = False
1+instance {-# OVERLAPPABLE #-} Eq Int where (==) _ _ = False
8
2
9instance
3instance
10− {-# OVERLAPPING #-} Ord Int where compare _ _ = GT
4+ {-# OVERLAPPING #-} Ord Int where compare _ _ = GT
11
5
12−instance {-# OVERLAPS #-} Eq Double where
6+instance {-# OVERLAPS #-} Eq Double where
13 (==) _ _ = False
7 (==) _ _ = False
14
8
15instance
9instance
16− {-# INCOHERENT #-} Ord Double where
10+ {-# INCOHERENT #-} Ord Double where
17 compare _ _ = GT
11 compare _ _ = GT
src/Ormolu/Diff.hs+8−1
@@ -9,6 +9,7 @@ module Ormolu.Diff
9 )
9 )
10where
10where
11
11
12+import BasicTypes (SourceText)
12import Data.Generics
13import Data.Generics
13import GHC
14import GHC
14import Ormolu.CommentStream
15import Ormolu.CommentStream
@@ -33,7 +34,10 @@ matchIgnoringSrcSpans = genericQuery
33 where
34 where
34 genericQuery :: GenericQ (GenericQ Bool)
35 genericQuery :: GenericQ (GenericQ Bool)
35 genericQuery x y = (toConstr x == toConstr y)
36 genericQuery x y = (toConstr x == toConstr y)
36− && and (gzipWithQ (genericQuery `extQ` srcSpanEq `extQ` hsModuleEq) x y)
37+ && and (gzipWithQ (genericQuery
38+ `extQ` srcSpanEq
39+ `extQ` hsModuleEq
40+ `extQ` sourceTextEq) x y)
37
41
38 srcSpanEq :: SrcSpan -> GenericQ Bool
42 srcSpanEq :: SrcSpan -> GenericQ Bool
39 srcSpanEq _ _ = True
43 srcSpanEq _ _ = True
@@ -46,3 +50,6 @@ matchIgnoringSrcSpans = genericQuery
46 matchIgnoringSrcSpans
50 matchIgnoringSrcSpans
47 hs0 { hsmodImports = sortImports (hsmodImports hs0) }
51 hs0 { hsmodImports = sortImports (hsmodImports hs0) }
48 hs1 { hsmodImports = sortImports (hsmodImports hs1) }
52 hs1 { hsmodImports = sortImports (hsmodImports hs1) }
53+
54+ sourceTextEq :: SourceText -> GenericQ Bool
55+ sourceTextEq _ _ = True