on master help sign in
Avoid crashing on unboxed string literals
f86e01emrkkrp
data/examples/declaration/value/function/unboxed-string-lit-out.hsnew file+3
@@ -0,0 +1,3 @@
1+{-# LANGUAGE MagicHash #-}
2+
3+main = new "p"#
data/examples/declaration/value/function/unboxed-string-lit.hsnew file+3
@@ -0,0 +1,3 @@
1+{-# LANGUAGE MagicHash #-}
2+
3+main = new "p"#
ormolu.cabal+1
@@ -38,6 +38,7 @@ flag dev
38library
38library
39 hs-source-dirs: src
39 hs-source-dirs: src
40 build-depends: base >= 4.12 && < 5.0
40 build-depends: base >= 4.12 && < 5.0
41+ , bytestring >= 0.2 && < 0.11
41 , containers >= 0.5 && < 0.7
42 , containers >= 0.5 && < 0.7
42 , dlist >= 0.8 && < 0.9
43 , dlist >= 0.8 && < 0.9
43 , exceptions >= 0.6 && < 0.11
44 , exceptions >= 0.6 && < 0.11
src/Ormolu/Diff.hs+7
@@ -11,6 +11,7 @@ module Ormolu.Diff
11where
11where
12
12
13import BasicTypes (SourceText)
13import BasicTypes (SourceText)
14+import Data.ByteString (ByteString)
14import Data.Generics
15import Data.Generics
15import GHC
16import GHC
16import Ormolu.Imports (sortImports)
17import Ormolu.Imports (sortImports)
@@ -51,6 +52,12 @@ matchIgnoringSrcSpans = genericQuery
51 where
52 where
52 genericQuery :: GenericQ (GenericQ Diff)
53 genericQuery :: GenericQ (GenericQ Diff)
53 genericQuery x y
54 genericQuery x y
55+ -- NOTE 'ByteString' implement 'Data' instance manually and does not
56+ -- implement 'toConstr', so we have to deal with it in a special way.
57+ | Just x' <- cast x, Just y' <- cast y =
58+ if x' == (y' :: ByteString)
59+ then Same
60+ else Different []
54 | typeOf x == typeOf y, toConstr x == toConstr y =
61 | typeOf x == typeOf y, toConstr x == toConstr y =
55 mconcat $ gzipWithQ
62 mconcat $ gzipWithQ
56 (genericQuery
63 (genericQuery