Skip to content

Commit c3351ea

Browse files
authored
Fix equivalence check for Date/Time/TimeZone (#2291)
This is fixing a bug where a temporal literal fails to type-check when given a type annotation (or more generally, when the type-checker checks it against an expected type). For example, the expression `00:00:00 : Date` would not type-check. The reason why is that `Dhall.Eval.conv` was missing cases for the `Date` / `Time` / `TimeZone` types and their respective literals, which this change fixes. I also fixed the test suite to catch future issues like this. We do have standard tests that check that temporal literals against expected types, but we were running the tests in such a way that we were not exercising the `Dhall.Eval.conv` code path that had this bug. So I updated the test suite so that it now catches this issue and future issues like this. I verified that the updated test suite now fails without this fix and passes with the fix.
1 parent 01e7048 commit c3351ea

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

dhall/src/Dhall/Eval.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,18 @@ conv !env t0 t0' =
981981
conv env t t'
982982
(VTextReplace a b c, VTextReplace a' b' c') ->
983983
conv env a a' && conv env b b' && conv env c c'
984+
(VDate, VDate) ->
985+
True
986+
(VDateLiteral l, VDateLiteral r) ->
987+
l == r
988+
(VTime, VTime) ->
989+
True
990+
(VTimeLiteral tl pl, VTimeLiteral tr pr) ->
991+
tl == tr && pl == pr
992+
(VTimeZone, VTimeZone) ->
993+
True
994+
(VTimeZoneLiteral l, VTimeZoneLiteral r) ->
995+
l == r
984996
(VList a, VList a') ->
985997
conv env a a'
986998
(VListLit _ xs, VListLit _ xs') ->

dhall/tests/Dhall/Test/TypeInference.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ successTest prefix = do
9797

9898
Tasty.HUnit.assertEqual message resolvedExpectedType inferredType
9999

100+
-- We also add this to exercise the `Dhall.Eval.conv` code path, since
101+
-- it's easy to forget to update it when adding new syntax
102+
_ <- Core.throws (TypeCheck.typeOf (Core.Annot resolvedExpr resolvedExpectedType))
103+
return ()
104+
100105
failureTest :: Text -> TestTree
101106
failureTest prefix = do
102107
let expectedFailures =

0 commit comments

Comments
 (0)