From 8b6ebce8e7ff2e409fd3dc6daf7e62101e2de00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Hangh=C3=B8j=20Iversen?= Date: Fri, 18 Oct 2019 00:02:29 +0200 Subject: [PATCH] Better comparison for values. --- src/Data/Language/Ruby/AST.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Data/Language/Ruby/AST.hs b/src/Data/Language/Ruby/AST.hs index 8eadf63..4ac6ee7 100644 --- a/src/Data/Language/Ruby/AST.hs +++ b/src/Data/Language/Ruby/AST.hs @@ -371,9 +371,10 @@ instance FromJSON Defs where compareValue :: Aeson.Value -> Aeson.Value -> Ordering compareValue v0 v1 = case (v0, v1) of - -- This case is buggy: - (Object o0, Object o1) -> compare (fst <$> toList o0) (fst <$> toList o1) - (Aeson.Array a0, Aeson.Array a1) -> foldMap (uncurry compareValue) $ zip (toList a0) (toList a1) + (Object o0, Object o1) -> mconcat $ zipWith go (toList o0) (toList o1) + where + go (t0, v0') (t1, v1') = compare t0 t1 <> compareValue v0' v1' + (Aeson.Array a0, Aeson.Array a1) -> mconcat $ zipWith compareValue (toList a0) (toList a1) (Aeson.String s0, Aeson.String s1) -> compare s0 s1 (Number n0, Number n1) -> compare n0 n1 (Bool b0, Bool b1) -> compare b0 b1