Skip to content

Commit

Permalink
Minor bug fixes for yaml-to-dhall error messages
Browse files Browse the repository at this point in the history
Fixes a type mismatch error message which mentions JSON.

Fixes an "arithmetic overflow" exception which occurs when attempting to
parse a negative number as a `Natural`.
  • Loading branch information
robbiemcmichael committed Sep 11, 2019
1 parent 23910e7 commit b1ace89
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions dhall-json/src/Dhall/JSONToDhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ import qualified Options.Applicative as O
import Options.Applicative (Parser)

import Dhall.JSON.Util (pattern V)
import qualified Dhall
import qualified Dhall.Core as D
import Dhall.Core (Expr(App), Chunks(..))
import qualified Dhall.Import
Expand Down Expand Up @@ -480,9 +479,9 @@ dhallFromJSON (Conversion {..}) expressionType =

-- number ~> Natural
loop D.Natural (A.Number x)
| Right n <- floatingOrInteger x :: Either Double Dhall.Natural
| Right n <- floatingOrInteger x :: Either Double Integer
, n >= 0
= Right (D.NaturalLit n)
= Right (D.NaturalLit (fromInteger n))
| otherwise
= Left (Mismatch D.Natural (A.Number x))

Expand Down Expand Up @@ -645,7 +644,7 @@ showCompileError format showValue = let prefix = red "\nError: "
where sep = red "\n--------\n" :: Text

Mismatch e v -> prefix
<> "Dhall type expression and json value do not match:"
<> "Dhall type expression and " <> format <> " value do not match:"
<> "\n\nExpected Dhall type:\n" <> showExpr e
<> "\n\n" <> format <> ":\n" <> showValue v
<> "\n"
Expand Down

0 comments on commit b1ace89

Please sign in to comment.