Skip to content

Commit c8402fa

Browse files
robbiemcmichaelmergify[bot]
authored andcommitted
Minor bug fixes for yaml-to-dhall error messages (#1305)
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`.
1 parent 23910e7 commit c8402fa

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

dhall-json/src/Dhall/JSONToDhall.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ import qualified Options.Applicative as O
236236
import Options.Applicative (Parser)
237237

238238
import Dhall.JSON.Util (pattern V)
239-
import qualified Dhall
240239
import qualified Dhall.Core as D
241240
import Dhall.Core (Expr(App), Chunks(..))
242241
import qualified Dhall.Import
@@ -480,9 +479,9 @@ dhallFromJSON (Conversion {..}) expressionType =
480479

481480
-- number ~> Natural
482481
loop D.Natural (A.Number x)
483-
| Right n <- floatingOrInteger x :: Either Double Dhall.Natural
482+
| Right n <- floatingOrInteger x :: Either Double Integer
484483
, n >= 0
485-
= Right (D.NaturalLit n)
484+
= Right (D.NaturalLit (fromInteger n))
486485
| otherwise
487486
= Left (Mismatch D.Natural (A.Number x))
488487

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

647646
Mismatch e v -> prefix
648-
<> "Dhall type expression and json value do not match:"
647+
<> "Dhall type expression and " <> format <> " value do not match:"
649648
<> "\n\nExpected Dhall type:\n" <> showExpr e
650649
<> "\n\n" <> format <> ":\n" <> showValue v
651650
<> "\n"

0 commit comments

Comments
 (0)