on master help sign in
Avoid crashing on unboxed string literals
commitf86e01ea3b7f606ed03a9971f42ae65b1fdcdb7c authormrkkrp <mark.karpov@tweag.io> dateSun 4 Aug 2019, 23:11 (7 years ago) parentbdb22b9
4 files changed+14
data/examples/declaration/value/function/unboxed-string-lit-out.hs+3 data/examples/declaration/value/function/unboxed-string-lit.hs+3 ormolu.cabal+1 src/Ormolu/Diff.hs+7
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
3838library
3939 hs-source-dirs: src
4040 build-depends: base >= 4.12 && < 5.0
41+ , bytestring >= 0.2 && < 0.11
4142 , containers >= 0.5 && < 0.7
4243 , dlist >= 0.8 && < 0.9
4344 , exceptions >= 0.6 && < 0.11
src/Ormolu/Diff.hs+7
@@ -11,6 +11,7 @@ module Ormolu.Diff
1111where
1212
1313import BasicTypes (SourceText)
14+import Data.ByteString (ByteString)
1415import Data.Generics
1516import GHC
1617import Ormolu.Imports (sortImports)
@@ -51,6 +52,12 @@ matchIgnoringSrcSpans = genericQuery
5152 where
5253 genericQuery :: GenericQ (GenericQ Diff)
5354 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 []
5461 | typeOf x == typeOf y, toConstr x == toConstr y =
5562 mconcat $ gzipWithQ
5663 (genericQuery