Skip to content

Commit

Permalink
Fix hashable-related test failures (#2152)
Browse files Browse the repository at this point in the history
Fixes #2151
  • Loading branch information
Gabriella439 authored Feb 26, 2021
1 parent 8f0518f commit ff263aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
3 changes: 2 additions & 1 deletion dhall-json/src/Dhall/JSONToDhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,8 @@ dhallFromJSON (Conversion {..}) expressionType =
, ("mapValue", val)
]

let records = (fmap f . Seq.fromList . HM.toList) keyExprMap
let records =
(fmap f . Seq.fromList . List.sort . HM.toList) keyExprMap

let typeAnn = if HM.null o then Just t else Nothing

Expand Down
20 changes: 7 additions & 13 deletions dhall/src/Dhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ import qualified Data.Functor.Compose
import qualified Data.Functor.Product
import qualified Data.HashMap.Strict as HashMap
import qualified Data.HashSet
import qualified Data.List
import qualified Data.List as List
import qualified Data.List.NonEmpty
import qualified Data.Map
import qualified Data.Maybe
Expand Down Expand Up @@ -1183,7 +1183,7 @@ setHelper size toSet (Decoder extractIn expectedIn) = Decoder extractOut expecte
vList = Data.Foldable.toList vSeq
vSet = toSet vList
sameSize = size vSet == Data.Sequence.length vSeq
duplicates = vList Data.List.\\ Data.Foldable.toList vSet
duplicates = vList List.\\ Data.Foldable.toList vSet
err | length duplicates == 1 =
"One duplicate element in the list: "
<> (Data.Text.pack $ show $ head duplicates)
Expand Down Expand Up @@ -1216,10 +1216,10 @@ map k v = fmap Data.Map.fromList (list (pairFromMapEntry k v))

{-| Decode a `HashMap` from a @toMap@ expression or generally a @Prelude.Map.Type@
>>> input (Dhall.hashMap strictText bool) "toMap { a = True, b = False }"
fromList [("a",True),("b",False)]
>>> input (Dhall.hashMap strictText bool) "[ { mapKey = \"foo\", mapValue = True } ]"
fromList [("foo",True)]
>>> fmap (List.sort . HashMap.toList) (input (Dhall.hashMap strictText bool) "toMap { a = True, b = False }")
[("a",True),("b",False)]
>>> fmap (List.sort . HashMap.toList) (input (Dhall.hashMap strictText bool) "[ { mapKey = \"foo\", mapValue = True } ]")
[("foo",True)]
If there are duplicate @mapKey@s, later @mapValue@s take precedence:
Expand Down Expand Up @@ -2198,13 +2198,7 @@ instance ToDhall a => ToDhall (Vector a) where
instance ToDhall a => ToDhall (Data.Set.Set a) where
injectWith = fmap (contramap Data.Set.toAscList) injectWith

{-| Note that the output list may not be sorted
>>> let x = Data.HashSet.fromList ["hi", "mom" :: Text]
>>> prettyExpr $ embed inject x
[ "mom", "hi" ]
-}
-- | Note that the output list may not be sorted
instance ToDhall a => ToDhall (Data.HashSet.HashSet a) where
injectWith = fmap (contramap Data.HashSet.toList) injectWith

Expand Down

0 comments on commit ff263aa

Please sign in to comment.