on master help sign in
Avoid comparing ‘SourceText’ when comparing ASTs
commit2dfd181c2f5cbc189cf70aced8dfabdd06778916 authormrkkrp <mark.karpov@tweag.io> dateSat 8 Jun 2019, 20:08 (7 years ago) parent5f5f922
3 files changed+12−16
data/examples/declaration/instance/overlappable-instances-out.hs−5 data/examples/declaration/instance/overlappable-instances.hs+4−10 src/Ormolu/Diff.hs+8−1
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.
61instance {-# OVERLAPPABLE #-} Eq Int where
72 (==) _ _ = False
83
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
82
93instance
10− {-# OVERLAPPING #-} Ord Int where compare _ _ = GT
4+ {-# OVERLAPPING #-} Ord Int where compare _ _ = GT
115
12−instance {-# OVERLAPS #-} Eq Double where
6+instance {-# OVERLAPS #-} Eq Double where
137 (==) _ _ = False
148
159instance
16− {-# INCOHERENT #-} Ord Double where
10+ {-# INCOHERENT #-} Ord Double where
1711 compare _ _ = GT
src/Ormolu/Diff.hs+8−1
@@ -9,6 +9,7 @@ module Ormolu.Diff
99 )
1010where
1111
12+import BasicTypes (SourceText)
1213import Data.Generics
1314import GHC
1415import Ormolu.CommentStream
@@ -33,7 +34,10 @@ matchIgnoringSrcSpans = genericQuery
3334 where
3435 genericQuery :: GenericQ (GenericQ Bool)
3536 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)
3741
3842 srcSpanEq :: SrcSpan -> GenericQ Bool
3943 srcSpanEq _ _ = True
@@ -46,3 +50,6 @@ matchIgnoringSrcSpans = genericQuery
4650 matchIgnoringSrcSpans
4751 hs0 { hsmodImports = sortImports (hsmodImports hs0) }
4852 hs1 { hsmodImports = sortImports (hsmodImports hs1) }
53+
54+ sourceTextEq :: SourceText -> GenericQ Bool
55+ sourceTextEq _ _ = True