Avoid crashing on unboxed string literals

This commit is contained in:
mrkkrp 2019-08-04 23:11:21 +02:00 committed by Mark Karpov
parent bdb22b96ac
commit f86e01ea3b
4 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,3 @@
{-# LANGUAGE MagicHash #-}
main = new "p"#

View File

@ -0,0 +1,3 @@
{-# LANGUAGE MagicHash #-}
main = new "p"#

View File

@ -38,6 +38,7 @@ flag dev
library
hs-source-dirs: src
build-depends: base >= 4.12 && < 5.0
, bytestring >= 0.2 && < 0.11
, containers >= 0.5 && < 0.7
, dlist >= 0.8 && < 0.9
, exceptions >= 0.6 && < 0.11

View File

@ -11,6 +11,7 @@ module Ormolu.Diff
where
import BasicTypes (SourceText)
import Data.ByteString (ByteString)
import Data.Generics
import GHC
import Ormolu.Imports (sortImports)
@ -51,6 +52,12 @@ matchIgnoringSrcSpans = genericQuery
where
genericQuery :: GenericQ (GenericQ Diff)
genericQuery x y
-- NOTE 'ByteString' implement 'Data' instance manually and does not
-- implement 'toConstr', so we have to deal with it in a special way.
| Just x' <- cast x, Just y' <- cast y =
if x' == (y' :: ByteString)
then Same
else Different []
| typeOf x == typeOf y, toConstr x == toConstr y =
mconcat $ gzipWithQ
(genericQuery